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.
Author |
Topic |
Mamatha
Posting Yak Master
102 Posts |
Posted - 2005-01-09 : 04:40:31
|
Hii 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 DSNtestset rs=conn.execute("select * from tbl_parameter where Databasename like '"& n1 &"' ")while not rs.EOFn3=rs("PathonDevelopment")rs.movenextwendSet rest=Server.CreateObject("SQLDMO.Restore")rest.Action=0 ' full db restorerest.Database= n1strpath=n3 & n1 & "\" & n2rest.Files ="["&strpath&"]"'rest.Files =strpath'response.write(rest.Files)rest.ReplaceDatabase=True 'Force restore over existing databaseDim objFSO , objDrive , drive'create an instance of FileSystemObjectSet objFSO = Server.CreateObject("Scripting.FileSystemObject")'Set objDrive = objFSO.DrivesFor Each drive in objFSO.Drivesif not drive="A:" thenSet objFolder = objFSO.GetFolder(drive&"\")'Response.Write(drive)for each folder in objFolder.subfoldersfor 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 nextnextend ifnext rest.SQLRestore(srv) set rs3=conn.execute("select * from tbl_Status") dim count cont=0while not rs3.EOF count=count+1rs3.MoveNext wendset rs3=nothingset rs3=conn.execute("select * from tbl_Status") while not rs3.EOFstrrs3=rs3(0)rs3.movenextwendif count >=9 thenset rs2=conn.execute("delete from tbl_Status where Status like '"& strrs3 &"'")strmsg=n2&" database file restored on development server at "& time & " on " & dateset rs1=conn.execute("insert into tbl_Status(Status)values('"&strmsg&"')")response.redirect("index.asp")elsestrmsg=n2&" database file restored on development server at "& time & " on " & dateset rs1=conn.execute("insert into tbl_Status(Status)values('"&strmsg&"')")response.redirect("index.asp")end ifset rest=nothingset srv=nothingset rs=nothingset rs1=nothingset rs2=nothingset rs3=nothingset 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 advanceMamatha |
|
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 thinghttp://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. |
|
|
|
|
|