Guest User

Untitled

a guest
Aug 6th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. Connection issue in C# WinForms application with multiple forms
  2. if (usertype == "UT1") //admin rights
  3. {
  4. //GET LOGGED USER
  5. Home_Admin homeAdmin = new Home_Admin();
  6. homeAdmin.SetUsername(username);
  7.  
  8. cString.Close();
  9. this.Close();
  10.  
  11. System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(OpenHomeAdmin));
  12. t.Start();
  13. }
  14.  
  15. private void backUpToolStripMenuItem_Click(object sender, EventArgs e)
  16. {
  17. BackUp BackUpForm = new BackUp();
  18. BackUpForm.Show();
  19. }
  20.  
  21. if(conn.State = connectionState.Open)
  22. {
  23. conn.close();
  24. }
  25.  
  26. public void BackupDatabase(String destinationPath)
  27. {
  28. SqlConnection cString = new SqlConnection();
  29. cString.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\MY_THESIS\WORKING FILES\NNIT-RMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
  30.  
  31. if (cString.State == ConnectionState.Open)
  32. {
  33. cString.Close();
  34. }
  35.  
  36. try
  37. {
  38. //MY SERVER
  39. String userName = "NNIT-Admin";
  40. String password = "password";
  41. String serverName = @"RITZEL-PCSQLEXPRESS";
  42.  
  43. ServerConnection connection = new ServerConnection(serverName, userName, password);
  44. Server sqlServer = new Server(connection);
  45.  
  46. Backup BackupMgr = new Backup();
  47. BackupMgr.Devices.AddDevice(destinationPath, DeviceType.File);
  48. BackupMgr.Database = "NNIT DB";
  49. BackupMgr.Action = BackupActionType.Database;
  50. BackupMgr.SqlBackup(sqlServer);
  51.  
  52. MessageBox.Show("Back up saved!");
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageBox.Show(ex.Message + " " + ex.InnerException);
  57. }
  58. }
  59.  
  60. private void BackUp_Load(object sender, EventArgs e)
  61. {
  62. string date = DateTime.Now.Day.ToString();
  63. string year = DateTime.Now.Year.ToString();
  64. string month = DateTime.Now.Month.ToString();
  65.  
  66. Filename_txt.Text = "NNIT-RMSDB_" + month + date + year;
  67. }
  68.  
  69. SqlConnection cString = new SqlConnection();
  70.  
  71. cString.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\MY_THESIS\WORKING FILES\NNIT-RMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
  72.  
  73. if (cString.State == ConnectionState.Open)
  74. {
  75. cString.Close();
  76. }
Add Comment
Please, Sign In to add comment