Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection issue in C# WinForms application with multiple forms
- 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();
- }
- private void backUpToolStripMenuItem_Click(object sender, EventArgs e)
- {
- BackUp BackUpForm = new BackUp();
- BackUpForm.Show();
- }
- if(conn.State = connectionState.Open)
- {
- conn.close();
- }
- 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);
- }
- }
- 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;
- }
- 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();
- }
Add Comment
Please, Sign In to add comment