Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.