|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Duplicating DatabaseHi all
Please any body tell how to duplicate an database within the same server from vb program? Use ADO or ADI.NET to send the SQL Server BACKUP and RESTORE commands.
-- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ Blog: http://solidqualitylearning.com/blogs/tibor/ <4vin***@gmail.com> wrote in message news:1135330125.702553.165800@g43g2000cwa.googlegroups.com... > Hi all > > Please any body tell how to duplicate an database within the same > server from vb program? > Thanks for the Reply
But when I restoring the database with another name there was Error says that you cannot overwrite the file... Just read about the RESTORE command in Books Online, and pay special attention to the MOVE option.
-- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ Blog: http://solidqualitylearning.com/blogs/tibor/ <4vin***@gmail.com> wrote in message news:1135333177.091629.6210@g47g2000cwa.googlegroups.com... > Thanks for the Reply > > But when I restoring the database with another name there was Error > says that you cannot overwrite the file... > Yes
I got the Solution conn.Execute "backup database DB_DATA to disk = '" & App.Path & "\db.bak'" rs.Open "RESTORE FILELISTONLY FROM DISK = '" & App.Path & "\db.bak'", conn, adOpenDynamic, adLockPessimistic Dim Dname As String, Lname As String Dim DFname As String, LFname As String Dname = rs("LogicalName") DFname = Left(rs("PhysicalName"), InStrRev(rs("PhysicalName"), "\")) & DBname & "_Data.mdf" rs.MoveNext Lname = rs("LogicalName") LFname = Left(rs("PhysicalName"), InStrRev(rs("PhysicalName"), "\")) & DBname & "_Log.ldf" conn.Execute "restore database " & DBname & " from disk = '" & App.Path & "\db.bak' WITH " & _ "MOVE '" & Dname & "' TO '" & DFname & "', " & _ "MOVE '" & Lname & "' TO '" & LFname & "'" Thanks |
|||||||||||||||||||||||