Created
January 13, 2018 18:14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool IsTenantProvisioned(string tenantSchema, DbConnection connection) | |
{ | |
// Execute plain SQL query to check for tenant schema existence | |
using(SqlConnection sqlConnection = new SqlConnection(connection.ConnectionString)) | |
{ | |
using(SqlCommand cmd = new SqlCommand()) | |
{ | |
cmd.Connection = sqlConnection; | |
cmd.CommandText = string.Format("SELECT COUNT(*) FROM sys.schemas WHERE name = '{0}'", tenantSchema); | |
cmd.CommandType = CommandType.Text; | |
try | |
{ | |
sqlConnection.Open(); | |
int total = (int) cmd.ExecuteScalar(); | |
if (total > 0) | |
{ | |
return true; | |
} else | |
{ | |
return false; | |
} | |
} catch (SqlException e) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment