Exemple #1
0
 public string GetConnectionStringForMasterDatabase()
 {
     return(ConnectionStringTemplate
            .Replace(ServerToken, ServerName)
            .Replace(UserIdToken, UserId)
            .Replace(PasswordToken, Password));
 }
Exemple #2
0
        protected override bool DBExists(string dbName)
        {
            bool   retVal  = false;
            string sql     = $"SELECT CONVERT(BIT, 1) FROM SYS.DATABASES WHERE [Name] = @dbName";
            string connStr = ConnectionStringTemplate.Replace(DBNAME_PLACEHOLDER, GetDefaultDatabase());

            using (var conn = GetOpenDBConnection(connStr))
            {
                retVal = conn.QueryFirstOrDefault <bool>(sql, new { dbName });
            }

            return(retVal);
        }
Exemple #3
0
        protected override void CreateDBIfNotExists(string dbName)
        {
            if (DBExists(dbName))
            {
                return;
            }

            string sql     = $"CREATE DATABASE [{dbName}]";
            string connStr = ConnectionStringTemplate.Replace(DBNAME_PLACEHOLDER, GetDefaultDatabase());

            using (var conn = GetOpenDBConnection(connStr))
            {
                conn.Execute(sql);
            }
        }