上面已经写出了,连接超时。
每次数据操作之后要关闭数据库!
你为什么把关闭数据库那句写在Exception里呢?
应该写在Finally里
依两位大匙的方法还是不行,因为我这个方法的作用是根据一个SQL语句,返回一个SqlDataReader,如果SqlConnection关闭了,就会在调用SqlDataReader.HasRows时及读取SqlDataReader.Read()时出错,如下图:
该方法的全部代码如下:
public SqlDataReader GetReader(string strSql, bool isProcess, params SqlParameter[] paras)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(strSql, conn);
            if (isProcess)
            {
                cmd.CommandType = CommandType.StoredProcedure;
            }
            if (paras != null)
            {
                foreach (SqlParameter p in paras)
                {
                    cmd.Parameters.Add(p);
                }
            }
            SqlDataReader sdr = null;
            try
            {
                conn.Open();
                sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (SqlException se)
            {
                MessageBox.Show(se.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return sdr;
        }

感觉楼主的代码逻辑太乱哦
楼主想用无参数SQL语句?带参数SQL语句?还是存储过程呢?
下面是一个用DataReader的简单示例 读NorthWind数据库
[CODE]            string conStr = "SERVER=(local);DATABASE=Northwind;INTEGRATED SECURITY=True;";
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdText = @"Select * From Customers";
                SqlCommand cmd = new SqlCommand(cmdText, con);
                SqlDataReader reader = cmd.ExecuteReader();
                int i = 0;
                while (reader.Read () )
                {
                    i++;
                }
                MessageBox.Show("OK"+" "+i);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }[/CODE]
