Thread th = new Thread(new ThreadStart(CreatDB)); th.Start(); public void CreatDB() { try { SqlConnection con2; conString2 = " Data Source=MC040;Initial Catalog= CurrentDataBaseName;Integrated Security=SSPI"; con2 = new SqlConnection(conString2); ServerConnection conn = new ServerConnection(con2); Server srv = new Server(conn); Transfer trsfrDB = new Transfer(srv.Databases[CurrentDataBaseName]); Microsoft.SqlServer.Management.Smo.Database newDatbase = new Microsoft.SqlServer.Management.Smo.Database(srv, "NewDBName"); newDatbase.Create(); ScriptingOptions options = new ScriptingOptions(); options.DriAll = true; options.ClusteredIndexes = true; options.Default = true; options.Indexes = true; trsfrDB.Options = options; trsfrDB.CopyAllObjects = true; trsfrDB.CopyAllViews = true; trsfrDB.CopyAllUsers = true; trsfrDB.CopyAllDefaults = true; trsfrDB.CopyAllDatabaseTriggers = true; trsfrDB.CopyAllUserDefinedTableTypes = true; trsfrDB.CopyAllSchemas = true; //Copy all user defined data types from source to destination trsfrDB.CopyAllUserDefinedDataTypes = true; //Copy all tables from source to destination trsfrDB.CopyAllTables = true; //Copy data of all source tables to destination tables //It actually generates INSERT statement for destination //trsfrDB.CopyData = true; //Copy all stored procedure from source to destination trsfrDB.CopyAllStoredProcedures = true; //specify the destination server name trsfrDB.DestinationServer = srv.Name; trsfrDB.DestinationLoginSecure = false; trsfrDB.DestinationLogin = "UserName"; trsfrDB.DestinationPassword = "Password"; trsfrDB.DestinationDatabase = "NewDBName"; trsfrDB.TransferData(); } catch (System.Exception ex) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)