Esempio n. 1
0
        public static string GetCurrentDatabaseName(SqlDbConnectionType strType)
        {
            SqlResult result = new SqliteCompiler().Compile(GetQueryConfig(strType).Select("query_string").Where("name", "current_db"));
            //return RunQueryTable("SELECT  FROM query_configs WHERE name = '' AND ");

            return "";
        }
Esempio n. 2
0
 public static void SwitchConnection(SqlDbConnectionType connectionType, string strConnectionString)
 {
     if (CurrentDatabase == null)
     {
         CurrentDatabase = new SqlDbConnection(connectionType, strConnectionString);
     }
     else
     {
         CurrentDatabase.Connection.ConnectionString = strConnectionString;
     }
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
 public static void ChangeDatabase(SqlDbConnectionType connectionType, string strDBName)
 {
     try
     {
         _strDatabase = strDBName;
         SwitchConnection(connectionType, _strServer, strDBName, _strUser, _strPass);
         if (CurrentDatabase.Connection.State != ConnectionState.Open)
         {
             CurrentDatabase.Connection.Open();
         }
         CurrentDatabase.Connection.ChangeDatabase(strDBName);
     }
     catch (Exception e) { }
 }
Esempio n. 5
0
        public void CompareDatabase(SqlDbConnectionType consType, Dictionary <string, SqlDbConnection> lstCons)
        {
            if (!CheckSelectedDB())
            {
                return;
            }
            switch (consType)
            {
            case SqlDbConnectionType.MySql:
                CompareDBMySql(lstCons);
                break;

            case SqlDbConnectionType.SqlServer:
                //(new TSQL.Tokens.
                break;
            }
        }
Esempio n. 6
0
        public static string GetDatabaseVersion(SqlDbConnectionType connectionType)
        {
            string strQuery = string.Empty;

            switch (connectionType)
            {
            case SqlDbConnectionType.MySql:
                strQuery = "SELECT VERSION()";
                break;

            case SqlDbConnectionType.SqlServer:
                strQuery = "";
                break;
            }
            DataTable dtData = RunQueryTable(strQuery);

            return(Convert.ToString(dtData.Rows[0][0]));
        }
Esempio n. 7
0
        public SqlDbConnection(SqlDbConnectionType connectionType, string connectionString)
        {
            _connectionType = connectionType;
            switch (connectionType)
            {
            case SqlDbConnectionType.MySql:
                _dbConnection = new MySqlConnection(connectionString);
                break;

            case SqlDbConnectionType.Sqlite:
                _dbConnection = new SQLiteConnection(connectionString);
                break;

            default:
                _dbConnection = new SqlConnection(connectionString);
                break;
            }
        }
Esempio n. 8
0
        public static string GetConnectionString(SqlDbConnectionType connectionType, String strServer, String strDatabase, String strUsername, String strPassword)
        {
            switch (connectionType)
            {
            case SqlDbConnectionType.MySql:
                string[] lstServer = strServer.Split(':');
                MySqlConnectionStringBuilder mysqlBuilder = new MySqlConnectionStringBuilder
                {
                    Server              = lstServer.FirstOrDefault(),
                    Port                = Convert.ToUInt32(lstServer.LastOrDefault()),
                    Database            = strDatabase,
                    UserID              = strUsername,
                    Password            = strPassword,
                    ConvertZeroDateTime = true,
                    AllowUserVariables  = true
                };

                _connectionString = mysqlBuilder.ConnectionString;
                break;

            case SqlDbConnectionType.Sqlite:
                var builder = new SQLiteConnectionStringBuilder
                {
                    DataSource = strServer,
                    Version    = 3
                };

                _connectionString = builder.ConnectionString;
                break;

            default:
                SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder
                {
                    DataSource     = strServer,
                    UserID         = strUsername,
                    Password       = strPassword,
                    InitialCatalog = strDatabase
                };
                _connectionString = sqlBuilder.ConnectionString;
                break;
            }
            return(_connectionString);
        }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
 public static void SetSqlDbConnectionType(SqlDbConnectionType connectionType)
 {
     _connectionType = connectionType;
 }
Esempio n. 11
0
        public void GetDatabaseVersion(SqlDbConnectionType connectionType)
        {
            string strVersion = SQLDBUtil.GetDatabaseVersion(connectionType);

            ShowMessengeInfo(strVersion);
        }
Esempio n. 12
0
 private static Query GetQueryConfig(SqlDbConnectionType strType)
 {
     return new Query("query_configs").Where("type", strType.ToString().ToLower());
 }