سلام
کدی که نوشتم اینه:
string MyDataBase = "dbase";
string MyPathName = Application.StartupPath;
string Master_CS = "Data Source=.\\sqlexpress;Integrated Security=True";
string MyDB_CS = "Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=" + MyDataBase + ";server=";
string MySP_Attached = @"EXEC sp_attach_db @dbname = N'" + MyDataBase + @"',@filename1 = N'" + MyPathName + @"\" + MyDataBase + @"_Data.MDF',@filename2 = N'" + MyPathName + @"\" + MyDataBase + @"_Log.LDF'";
try
{
var C = new SqlConnection(Master_CS);
C.Open();
new SqlCommand(MySP_Attached, C).ExecuteNonQuery();
C.Close();
}
catch
{
MessageBox.Show("0");
}
try
{
string MyDB = "dbase";
var C = new SqlConnection("Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=" + MyDB + ";server=");
C.Open();
new SqlCommand(@"BacKUpApplication 'D:\','" + MyDB + "'", C).ExecuteNonQuery();
}
catch
{
MessageBox.Show("1");
}
الان بازم جواب نمیده و تو جفه catch ها میره
ایرادش چیه؟