Cloning a Database with VB.Net

  • Thread starter Thread starter George Shubin
  • Start date Start date
G

George Shubin

Using SQL Server 2005 Express.

I need to periodically duplicate an entire database and rename it. Most
tables are empty but some are to be prepopulated. I was thinking of having
a "template" database called perhaps "EmptyDatabase", and then copy that
into a freshly created database with a new name.

Has anyone coded anything like this?

Thanks.

GS
 
George,
Try SMO.

The assembly Microsoft.SqlServer.Smo.dll (and supporting DLLs
Microsoft.SqlServer.ConnectionInfo.dll and Microsoft.SqlServer.SmoEnum.dll
etc) can be found in C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies.

Have a look at the Server (server.AttachDatabase and server.DetachDatabase),
Backup and Restore classes.

SMO is also backward compatible with SQL Server 2000 and 7 (but with reduced
functionality).

All the best.
Phil.
 
Thanks, Phil.

I take a look.

GS


Phil Williams said:
George,
Try SMO.

The assembly Microsoft.SqlServer.Smo.dll (and supporting DLLs
Microsoft.SqlServer.ConnectionInfo.dll and Microsoft.SqlServer.SmoEnum.dll
etc) can be found in C:\Program Files\Microsoft SQL
Server\90\SDK\Assemblies.

Have a look at the Server (server.AttachDatabase and
server.DetachDatabase),
Backup and Restore classes.

SMO is also backward compatible with SQL Server 2000 and 7 (but with
reduced
functionality).

All the best.
Phil.
 
Back
Top