Guest User

Untitled

a guest
Jan 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. protected void Connection(object sender, EventArgs e)
  2. {
  3. string User = "";
  4. string Password = "";
  5. string Istanza = "";
  6. SqlConnection myConnection = null;
  7. try
  8. {
  9. User = LoginName1.Value;
  10. Password = Password1.Value;
  11. Istanza = DropDownIstance.SelectedItem.ToString();
  12. myConnection = new SqlConnection("user id="+User+";" +
  13. "password="+ Password + ";Data Source=" + Istanza + ";" +
  14. "Trusted_Connection=yes;" +
  15. "Database=main;" +
  16. "connection timeout=30");
  17.  
  18. myConnection.Open();
  19.  
  20. // Set up a command with the given query and associate
  21. // this with the current connection.
  22. using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases", myConnection))
  23. {
  24. using (IDataReader dr = cmd.ExecuteReader())
  25. {
  26. while (dr.Read())
  27. {
  28. DropDownListDB.Items.Add(dr[0].ToString());
  29. }
  30. }
  31. }
  32.  
  33.  
  34. }
  35. catch (Exception Err)
  36. {
  37. string ErrorMessage = Err.Message;
  38. }
  39. finally
  40. {
  41. myConnection.Close();
  42. }
  43. }
  44.  
  45. protected void Connection(object sender, EventArgs e)
  46. {
  47. string User = "";
  48. string Password = "";
  49. string Istanza = "";
  50. SqlConnection myConnection = null;
  51. try
  52. {
  53. User = LoginName1.Value;
  54. Password = Password1.Value;
  55. Istanza = DropDownIstance.SelectedItem.ToString();
  56. myConnection = new SqlConnection("Server=" + Istanza + ";" +
  57. "Database=master;" +
  58. "User ID=" + LoginName1.Value.Trim() + ";" +
  59. "Password=" + Password1.Value.Trim() + ";" +
  60. "Trusted_Connection=False");
  61.  
  62. myConnection.Open();
  63.  
  64.  
  65. // Set up a command with the given query and associate
  66. // this with the current connection.
  67. using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases", myConnection))
  68. {
  69. using (IDataReader dr = cmd.ExecuteReader())
  70. {
  71. while (dr.Read())
  72. {
  73. DropDownListDB.Items.Add(dr[0].ToString());
  74. }
  75. }
  76. }
  77.  
  78.  
  79. }
  80. catch (Exception Err)
  81. {
  82. string ErrorMessage = Err.Message;
  83. }
  84. finally
  85. {
  86. myConnection.Close();
  87. }
  88. }
Add Comment
Please, Sign In to add comment