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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 To copy database - SMO

Author  Topic 

next78
Starting Member

9 Posts

Posted - 2008-06-27 : 16:12:43
Hi,

I need to copy a database and its tables using SMO (SQL Server Management Objects).

How I can copy a database using Vb.net?

I tried some examples but it only copies DB but not the tables...

code examples:

http://msdn.microsoft.com/en-us/library/ms162138.aspx
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=862223&SiteID=17

thanks in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-27 : 16:13:29
Just use BACKUP/RESTORE.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

next78
Starting Member

9 Posts

Posted - 2008-06-28 : 06:19:54
Yes, yesterday I tried to backup DB and restore with other name...but then I should create the .MDF and .LDF for this new DB. But to do these I should share this directory of the Server and I do not want.

There has to be a way without having to share directories of the server
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-28 : 17:57:09
You do not need to create the MDF or the LDF, and you do not need to create a share. The restore takes care of everything.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

next78
Starting Member

9 Posts

Posted - 2008-06-29 : 06:41:18
Nop, it displays an error if I restore the backup with other name.

The file MYDB_Copy.LDF can not overwritten because is used by MYDB
The file MYDB_Copy.MDF can not overwritten because is used by MYDB
Go to Top of Page

next78
Starting Member

9 Posts

Posted - 2008-06-29 : 07:17:09
If I create a backup backupDB.bak of the MyDB, and after I restore it, it runs ok. But If I try to restore a backup with a name different of the original, it displays error.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-29 : 13:51:56
You need to use the WITH MOVE option of the RESTORE command.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -