title: SqlServer Class static methods - Thread Safety
body: <p>I have created a class to ease the use of SQL server within my app.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static class SqlServer
  {        
      public static void QueryNoReturn(string ConnectionString, string Query, SqlParameter[] Parameters, bool IsStoredProcedure)
      {
          using (SqlConnection conn = new SqlConnection(ConnectionString))
          {
              // Create the command to run
              SqlCommand command = new SqlCommand(Query, conn);
  
              // If we are running a stored procedure
              if (IsStoredProcedure)
                  command.CommandType = System.Data.CommandType.StoredProcedure;
  
              // Add parameters if they exist
              if (Parameters != null)
                  command.Parameters.AddRange(Parameters);
  
              try
              {
                  // Open the connection to the database
                  conn.Open();
  
                  // Execute the command and assign to the result object
                  command.ExecuteNonQuery();
  
                  conn.Close();
  
                  command.Parameters.Clear();
              }
              catch (SqlException sqlex)
              {
                  throw new Exception(
                      string.Format("{0} \"{1}\"", IsStoredProcedure ? "Procedure" : "Query", Query),
                      sqlex);
              }
          }
      }
  }
  </code></pre>
  
  <p>If I am calling this static method many times a second (approx. 50) then will I see issues with thread safety?</p>
  
  <p>I could easily create a <code>Factory</code> or some other instance specific object, but I went with this option out of simplicity.</p>