日期:2014-05-18  浏览次数:20744 次

帮忙看看这个数据库的访问类是否有问题?
请大家帮忙,帮忙看看这个数据库的访问类是否有问题?  
如果是一个操作基本没有什么问题,但是同时有很多人使用的时候就报错。
以下是代码


 public class SQLServerHelper
  {
  private static string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

  public static void AddParamInCmd(SqlCommand cmd, string paramName, SqlDbType type, int size, object value)
  {
  SqlParameter parameter = new SqlParameter();
  parameter.ParameterName = paramName;
  parameter.SqlDbType = type;
  parameter.Size = size;
  parameter.Value = value;
  cmd.Parameters.Add(parameter);
  }

  private static SqlCommand BuildIntCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
  {
  SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);
  command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null));
  return command;
  }

  private static SqlCommand BuildQueryCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
  {
  SqlCommand command = new SqlCommand(storedProcName, connection);
  command.CommandType = CommandType.StoredProcedure;
  foreach (SqlParameter parameter in parameters)
  {
  command.Parameters.Add(parameter);
  }
  return command;
  }

  public static int ExecuteNonQuery(SqlTransaction transaction, string commandText, params SqlParameter[] commandParameters)
  {
  SqlCommand cmd = new SqlCommand();
  PrepareCommand(cmd, transaction.Connection, transaction, commandText, commandParameters);
  int num = cmd.ExecuteNonQuery();
  cmd.Parameters.Clear();
  return num;
  }

  public static SqlDataReader ExecuteReader(string sqlString)
  {
  SqlDataReader reader2;
  SqlConnection connection = new SqlConnection(connectionString);
  SqlCommand command = new SqlCommand(sqlString, connection);
  SqlDataReader reader = null;
  try
  {
  connection.Open();
  reader = command.ExecuteReader(CommandBehavior.CloseConnection);
  reader2 = reader;
  }
  catch (SqlException exception)
  {
  connection.Close();
  throw new Exception(exception.Message);
  }
  finally
  {
  if (reader == null)
  {
  command.Dispose();
  connection.Close();
  }
  }
  return reader2;
  }

  public static SqlDataReader ExecuteReader(string sqlString, params SqlParameter[] cmdParms)
  {
  SqlDataReader reader2;
  SqlConnection conn = new SqlConnection(connectionString);
  SqlCommand cmd = new SqlCommand();
  SqlDataReader reader = null;
&nb