当我提出申请时,尽管我尚未开始申请,但还是装上了装饰/初步写上了所有形式? (I.E. Form.Show)
这就是我如何关闭标志形式的连接:
if (usertype == "UT1") //admin rights
{
//GET LOGGED USER
Home_Admin homeAdmin = new Home_Admin();
homeAdmin.SetUsername(username);
cString.Close();
this.Close();
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(OpenHomeAdmin));
t.Start();
}
以及我如何从家庭到Admin s菜单的背书
private void backUpToolStripMenuItem_Click(object sender, EventArgs e)
{
BackUp BackUpForm = new BackUp();
BackUpForm.Show();
}
I am trying to create a back up of my database and it works perfectly if I run only the back up form. If I start the app from the very beginning, it says back up failed the database is in use. I already closed the connection from login to the form where I will launch the back up form and even set a
if(conn.State = connectionState.Open)
{
conn.close();
}
在备份程序之前。 无论怎么说,我只能杀掉与SQ >数据库的所有链接;后又恢复链接?。
<>BACK UP CODE
public void BackupDatabase(String destinationPath)
{
SqlConnection cString = new SqlConnection();
cString.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\MY_THESIS\WORKING FILES\NNIT-RMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
if (cString.State == ConnectionState.Open)
{
cString.Close();
}
try
{
//MY SERVER
String userName = "NNIT-Admin";
String password = "password";
String serverName = @"RITZEL-PCSQLEXPRESS";
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Backup BackupMgr = new Backup();
BackupMgr.Devices.AddDevice(destinationPath, DeviceType.File);
BackupMgr.Database = "NNIT DB";
BackupMgr.Action = BackupActionType.Database;
BackupMgr.SqlBackup(sqlServer);
MessageBox.Show("Back up saved!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " " + ex.InnerException);
}
}
<>strong>FORM LOAD
private void BackUp_Load(object sender, EventArgs e)
{
string date = DateTime.Now.Day.ToString();
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
Filename_txt.Text = "NNIT-RMSDB_" + month + date + year;
}
Error message http://img824.imageshack.us/img824/8541/error1lj.jpg