DataBase.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.SqlClient;
  7. namespace Blanki_ekzamena
  8. {
  9. internal class DataBase
  10. {
  11. static SqlConnection SqlConnection = new SqlConnection(@"Data Source=ngknn.ru;Initial Catalog=31P_Trifonova_PP;User ID=31П;Password=12357");
  12. public static void openConnection()
  13. {
  14. if (SqlConnection.State == System.Data.ConnectionState.Closed)
  15. {
  16. SqlConnection.Open();
  17. }
  18. }
  19. public static void closeConnection()
  20. {
  21. if (SqlConnection.State == System.Data.ConnectionState.Open)
  22. {
  23. SqlConnection.Close();
  24. }
  25. }
  26. public static SqlConnection GetConnection()
  27. {
  28. return SqlConnection;
  29. }
  30. public static SqlConnection connect()
  31. {
  32. string location = Environment.CurrentDirectory;
  33. location = location.Remove(location.Length - 9, 9);
  34. location = location.Insert(location.Length, "Database1.mdf");
  35. string connectionString = @"Data Source=ngknn.ru;Initial Catalog=31P_Trifonova_PP;User ID=31П;Password=12357";
  36. SqlConnection sqlConnection = new SqlConnection(connectionString);
  37. sqlConnection.Open();
  38. return sqlConnection;
  39. }
  40. }
  41. }