public string GetConnectionStringForMasterDatabase() { return(ConnectionStringTemplate .Replace(ServerToken, ServerName) .Replace(UserIdToken, UserId) .Replace(PasswordToken, Password)); }
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); }
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); } }