Guest User

Untitled

a guest
Jan 10th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 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. }
Add Comment
Please, Sign In to add comment