Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }