Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. private static bool IsTenantProvisioned(string tenantSchema, DbConnection connection)
  2.  {
  3.  // Execute plain SQL query to check for tenant schema existence
  4.  using (SqlConnection sqlConnection = new SqlConnection(connection.ConnectionString))
  5.  {
  6.  using (SqlCommand cmd = new SqlCommand())
  7.  {
  8.  cmd.Connection = sqlConnection;
  9.  cmd.CommandText = string.Format("SELECT COUNT(*) FROM sys.schemas WHERE name = '{0}'", tenantSchema);
  10.  cmd.CommandType = CommandType.Text;
  11.  try
  12.  {
  13.  sqlConnection.Open();
  14.  int total = (int)cmd.ExecuteScalar();
  15.  
  16.  if (total > 0)
  17.  {
  18.  return true;
  19.  }
  20.  else
  21.  {
  22.  return false;
  23.  }
  24.  }
  25.  catch (SqlException e)
  26.  {
  27.  return false;
  28.  }
  29.  }
  30.  }
  31.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement