ممنون از دوستان خودم نوشتمش کدشم میزارم که اگه کسی خواست استفاده کنه
using System.Threading;
.
.
.
InitializeComponent();
th = new Thread(new ThreadStart(CreatDB));
th.IsBackground = true;
.
.
.
private void btnCreatDB_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
th.Start();
}
public void CreatDB()
{
try
{
ServerConnection conn = new ServerConnection(".", "UserName", "Password");
Server srv = new Server(conn);
Transfer trsfrDB = new Transfer(srv.Databases[db.Connection.Database]);
Database newDatbase = new Database(srv, dbName + Year);
newDatbase.Create();
ScriptingOptions options = new ScriptingOptions();
options.DriAll = true;
options.ClusteredIndexes = true;
options.Default = true;
// options.DriAll = true;
options.Indexes = true;
//options.IncludeHeaders = true;
//options.AppendToFile = false;
//options.ToFileOnly = true;
trsfrDB.Options = options;
trsfrDB.CopyAllObjects = true;
trsfrDB.CopyAllViews = true;
trsfrDB.CopyAllUsers = true;
//trsfrDB.CopySchema = 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 = dbName + Year;
trsfrDB.TransferData();
}
catch (System.Exception ex)
{
MessageBox.Show(this, "ایجاد پایگاه داده جدید با خطا مواجه شده است.مجددا تلاش نمایید", "خطا درایجاد پایگاه داده جدید", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
finally
{
this.Cursor = Cursors.Arrow;
MessageBox.Show(this, "پایگاه داده مورد نظر با موفقیت ایجاد شد", "ایجاد پایگاه داده جدید", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
th.Abort();
}
}