예제 #1
0
        public static bool CanConnect(SqlDBHandle sqlDb)
        {
            bool   canConnect = false;
            string dbName     = sqlDb.DBName;

            sqlDb.DBName = "master";
            SqlConnection sqlConnection = new SqlConnection(sqlDb.ConnectionString);

            try {
                sqlConnection.Open();
                canConnect = true;
                sqlConnection.Close();
            } catch { }
            if (!canConnect)
            {
                return(false);
            }
            sqlDb.DBName = dbName;
            if (!SqlDbExists(sqlDb))
            {
                return(true);
            }
            canConnect    = false;
            sqlConnection = new SqlConnection(sqlDb.ConnectionString);
            try {
                sqlConnection.Open();
                canConnect = true;
                sqlConnection.Close();
            } catch { }
            return(canConnect);
        }
예제 #2
0
        public static void DeleteSqlDb(SqlDBHandle sqlDb)
        {
            string dbName = sqlDb.DBName;

            sqlDb.DBName = null;
            var sqlConnection = new MySqlConnection(sqlDb.ConnectionString);

            sqlConnection.Open();
            new MySqlCommand("DROP DATABASE " + dbName, sqlConnection).ExecuteNonQuery();
        }
예제 #3
0
        public static bool SqlDbExists(SqlDBHandle sqlDb)
        {
            string commandText = "select * from master.dbo.sysdatabases where name=\'" + sqlDb.DBName + "\'";

            sqlDb.DBName = "videorent";
            bool ret = true;

            using (var sqlConnection = new MySqlConnection(sqlDb.ConnectionString))
                try {
                    sqlConnection.Open();
                    //using (var sqlCommand = new MySqlCommand(commandText, sqlConnection))
                    //{
                    //    var reader = sqlCommand.ExecuteReader();
                    //    ret = reader.HasRows;
                    //    reader.Close();
                    //}
                    sqlConnection.Close();
                } catch (MySqlException) {
                    ret = false;
                }
            return(ret);
        }