Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Permission denide error

Author  Topic 

Mamatha
Posting Yak Master

102 Posts

Posted - 2005-01-09 : 04:40:31
Hi
i hava wrote the code to restore a file of SQL server database through ASP.It can access the backup file on server and restored but some times or in some systems it gives error like permission denide.What is the reason for that.
Here is the code:

<!--#Include File="Connect.inc"-->

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Intranet FTP&SQL Server Control</title>
</head>

<body>
<%
n1=request.querystring("nn1")
n2=request.querystring("nn2")
nd=request.querystring("nn3")
nt=request.querystring("nn4")

Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.Connect "server", "sa","thanks"
'Set Conn = Server.CreateObject("ADODB.Connection")
'DSNtest="DRIVER={SQL Server};SERVER=SERVER;UID=sa;PWD=thanks;DATABASE=parameter"
'Conn.open DSNtest
set rs=conn.execute("select * from tbl_parameter where Databasename like '"& n1 &"' ")
while not rs.EOF
n3=rs("PathonDevelopment")
rs.movenext
wend

Set rest=Server.CreateObject("SQLDMO.Restore")
rest.Action=0 ' full db restore
rest.Database= n1
strpath=n3 & n1 & "\" & n2
rest.Files ="["&strpath&"]"
'rest.Files =strpath
'response.write(rest.Files)
rest.ReplaceDatabase=True 'Force restore over existing database

Dim objFSO , objDrive , drive
'create an instance of FileSystemObject
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Set objDrive = objFSO.Drives

For Each drive in objFSO.Drives
if not drive="A:" then
Set objFolder = objFSO.GetFolder(drive&"\")
'Response.Write(drive)
for each folder in objFolder.subfolders

for each folder_main in folder.subfolders

for each folder_sub in folder_main.subfolders


for each folder_files in folder_sub.subfolders

if folder_files.name = "Data" then

rest.RelocateFiles = "["&n1&"_Data]" & "," & _
"["&folder_sub&"\Data\"&n1&".mdf]" & "," & _
"["&n1&"_Log]" & "," & _
"["&folder_sub&"\Data\"&n1&"_log.ldf]"

exit for
end if
next

next
next
next
end if
next


rest.SQLRestore(srv)

set rs3=conn.execute("select * from tbl_Status")
dim count
cont=0
while not rs3.EOF
count=count+1
rs3.MoveNext
wend
set rs3=nothing
set rs3=conn.execute("select * from tbl_Status")
while not rs3.EOF
strrs3=rs3(0)
rs3.movenext
wend
if count >=9 then
set rs2=conn.execute("delete from tbl_Status where Status like '"& strrs3 &"'")
strmsg=n2&" database file restored on development server at "& time & " on " & date
set rs1=conn.execute("insert into tbl_Status(Status)values('"&strmsg&"')")
response.redirect("index.asp")


else
strmsg=n2&" database file restored on development server at "& time & " on " & date
set rs1=conn.execute("insert into tbl_Status(Status)values('"&strmsg&"')")
response.redirect("index.asp")

end if

set rest=nothing
set srv=nothing

set rs=nothing
set rs1=nothing
set rs2=nothing
set rs3=nothing
set Conn=nothing
%>
</body>

</html>

or some times it gives error like,path not found at the time of getting folders from drives.What the mistake happen in my code.
Please give me a qucik solution,because this is very urgent for me.
Thanks in advance



Mamatha

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-09 : 05:01:52
My guess is that the sql server service can't access the backup file.

As for path not found - maybe off line network paths or dvd drives?

Why are you doing this in asp? You have to have a database existing to run this so why not do it in an SP?
Here's an example of te sort of thing

http://www.mindsdoor.net/SQLAdmin/s_TestRestore.html

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -