Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private SqlConnection connection = null;
- private SqlCommand cmd;
- private SqlDataReader reader;
- private bool IsDatabaseOpen = false;
- private string _DB = null;
- private cp_ini _c;
- public cp_db(string db)
- {
- _c = new cp_ini(Environment.CurrentDirectory + @"\Config\Config.cfg");
- string host = _c.Read("host", "Config");
- string user = _c.Read("username", "Config");
- string password = _c.Read("password", "Config");
- SqlConnectionStringBuilder SqlConnection = new SqlConnectionStringBuilder();
- SqlConnection.DataSource = host;
- SqlConnection.UserID = user;
- SqlConnection.Password = password;
- SqlConnection.InitialCatalog = db;
- SqlConnection.MultipleActiveResultSets = true;
- string connection_string = SqlConnection.ToString();
- Console.WriteLine("Connecting to a SQL Server...");
- Console.WriteLine(connection_string);
- connection = new SqlConnection(connection_string);
- _DB = db;
- this.IsDatabaseOpen = Open();
- }
- private bool Open()
- {
- bool isOpen = false;
- if (connection != null)
- {
- try
- {
- connection.Open();
- }
- catch (SqlException ex)
- {
- throw ex;
- }
- finally
- {
- if (connection.State == ConnectionState.Open) isOpen = true;
- Console.WriteLine("SQL Server -> Connection has been successfully established");
- }
- }
- return isOpen;
- }
- public bool DBStatusOpen()
- {
- return this.IsDatabaseOpen;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement