Home All Groups Group Topic Archive Search About
Author
23 Dec 2005 9:28 AM
4vinoth
Hi all

Please any body tell how to duplicate an database within the same
server from vb program?

Author
23 Dec 2005 9:31 AM
Tibor Karaszi
Use ADO or ADI.NET to send the SQL Server BACKUP and RESTORE commands.

Show quote
<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?
>
Author
23 Dec 2005 10:19 AM
4vinoth
Thanks for the Reply

But when I restoring the database with another name there was Error
says that you cannot overwrite the file...
Author
23 Dec 2005 10:46 AM
Tibor Karaszi
Just read about the RESTORE command in Books Online, and pay special attention to the MOVE option.

Show quote
<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...
>
Author
23 Dec 2005 12:14 PM
4vinoth
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

AddThis Social Bookmark Button