Exemplo n.º 1
0
 public static void SwitchConnection(SqlDbConnectionType connectionType, string strConnectionString)
 {
     if (CurrentDatabase == null)
     {
         CurrentDatabase = new SqlDbConnection(connectionType, strConnectionString);
     }
     else
     {
         CurrentDatabase.Connection.ConnectionString = strConnectionString;
     }
 }
Exemplo n.º 2
0
 static SqlDatabaseHelper()
 {
     try
     {
         _connectionType = SqlDbConnectionType.SqlServer;
         CurrentDatabase = new SqlDbConnection(_connectionType, GetConnectionString(_connectionType, _strServer, _strDatabase, _strUser, _strPass));
     }
     catch (Exception exception)
     {
         MessageBox.Show("Can not connect to server - " + _strServer, "Messenger", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemplo n.º 3
0
 public static void SwitchConnection(SqlDbConnectionType connectionType, String strServers, String strDatabases, String strUsernames, String strPasswords)
 {
     try
     {
         _connectionType = connectionType;
         if (!string.IsNullOrEmpty(strServers) || strServers != _strServer)
         {
             _strServer = strServers;
         }
         if (!string.IsNullOrEmpty(strDatabases) || strDatabases != _strDatabase)
         {
             _strDatabase = strDatabases;
         }
         if (!string.IsNullOrEmpty(strUsernames) || strUsernames != _strUser)
         {
             _strUser = strUsernames;
         }
         if (!string.IsNullOrEmpty(strPasswords) || strPasswords != _strPass)
         {
             _strPass = strPasswords;
         }
         if (CurrentDatabase == null)
         {
             CurrentDatabase = new SqlDbConnection(connectionType, GetConnectionString(connectionType, _strServer, _strDatabase, _strUser, _strPass));
         }
         else if (!CurrentDatabase.Connection.GetType().Name.StartsWith(SqlDbConnectionType.MySql.ToString()))
         {
             CurrentDatabase = new SqlDbConnection(connectionType, GetConnectionString(connectionType, _strServer, _strDatabase, _strUser, _strPass));
         }
         else if (!CurrentDatabase.Connection.GetType().Name.StartsWith("Sql"))
         {
             CurrentDatabase = new SqlDbConnection(connectionType, GetConnectionString(connectionType, _strServer, _strDatabase, _strUser, _strPass));
         }
         else if (CurrentDatabase.Connection.State == ConnectionState.Closed)
         {
             CurrentDatabase.Connection.ConnectionString = GetConnectionString(connectionType, _strServer, _strDatabase, _strUser, _strPass);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Can't not change connection!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }