static private SqlCommand cmd; private static SqlConnection conn; static private readonly string connString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; //从web.config获取数据库连接字符串 public static SqlConnection Conn { get { if (conn == null) { conn = new SqlConnection(connString); conn.Open(); } else if (conn.State == ConnectionState.Broken) { conn.Close(); conn.Open(); } else if (conn.State == ConnectionState.Closed) { conn.Open(); } return conn; } } static SqlHelpers() { cmd = new SqlCommand(); cmd.Connection = Conn; cmd.CommandType = CommandType.StoredProcedure; } /// <summary>通过存储过程,返回DataTable结果集 /// </summary> /// <param name="parName">存储过程名</param> /// <param name="pars">存储过程参数</param> /// <returns></returns> public DataTable GetDataTable(string parName, SqlParameter[] pars) { try { cmd.CommandText = parName; if (pars != null && pars.Length > 0) { foreach (SqlParameter item in pars) { cmd.Parameters.Add(item); } } DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); cmd.Parameters.Clear(); return dt; } catch (Exception) { cmd.Parameters.Clear(); return null; } }
我自己弄的网站,数据库连接是这么写的,但是我测试的时候,同时并发人数达到200人的时候,就会出现找不到数据库中的某个字段,但是重新上传一下dll文件就能找到了!我怀疑是数据库连接语句的问题,菜鸟求教……
holdtom
翻阅古今
心有法竹
长风秋雁
海绵宝宝撒