问题提示:1.阅读器关闭时 Read 的尝试无效。2.未将对象引用设置到对象的实例。3.内部连接致命错误。4.不允许更改“ConnectionString”属性。连接的当前状态为正在连接。
以上错误都会出现。一般运行程序时都没问题就是偶尔来一下。(程序是C#)
错误源码:行 166:        catch (Exception e)
行 167:        {
行 168:            throw new Exception(e.Message); //提示这行有问题
行 169:        }
行 170:        finally完整源码:    /// <summary> 
    /// 执行Sql查询语句并返回第一行的第一条记录,返回值为object 使用时需要拆箱操作 -> Unbox 
    /// </summary> 
    /// <param name="sqlstr">传入的Sql语句</param> 
    /// <returns>object 返回值 </returns> 
    public static object ExecuteScalar(string sqlstr)
    {
        object obj = new object();
        SqlCommand comm = new SqlCommand();
        try
        {
            openConnection();
            comm.Connection = conn;
            comm.CommandType = CommandType.Text;
            comm.CommandText = sqlstr;
            obj = comm.ExecuteScalar();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        finally
        {
            comm.Dispose(); 
            closeConnection();
        }
        return obj;
    }
调用的源码:    public string Get_SQL_OnlyRecord(string sql)
    {
        return PS_Conn.ExecuteScalar(sql).ToString();
    }
   
    public string Get_Focus_Img() 
    { 
        
        string dataSet = Get_SQL_OnlyRecord("select FocusImg from PS_WebSet where ID = 1"); 
       
        string FocusList = "\r\n";
        int Order = 0;
        string[] sArray = Regex.Split(dataSet, ",", RegexOptions.IgnoreCase);
        foreach (string i in sArray)
        {
            Order++;
            if (Order <= 4)
            {
                string BookID = i.ToString();
                string BookImg = Get_SQL_OnlyRecord("select BookCover from ps_books where bookid = " + BookID + "");
                string BookName = Get_SQL_OnlyRecord("select BookName from ps_books where bookid = " + BookID + "");
                string BookIntro = Get_SQL_OnlyRecord("select BookIntro from ps_books where bookid = " + BookID + "");
                
                FocusList += "                imgUrl[" + Order + "]='/uploadfiles/" + BookImg + "';\r\n";
                FocusList += "                imgSUrl[" + Order +"]='/uploadfiles/" + BookImg + "';\r\n";
                FocusList += "                imgtext[" + Order + "]='<a href=\"/book/" + BookID + "/\">" + BookName + "</a>';\r\n";
                FocusList += "                imgLink[" + Order + "]='/book/" + BookID + "/';\r\n";
                FocusList += "                imgAlt[" + Order + "]='" + BookName + "';\r\n";
                FocusList += "                imgIntro[" + Order + "]='" + PS_Site.Substring(PS_Site.NoAllHTML(BookIntro), 60) + "<a href=\"/book/" + BookID + "/\">[详细]</a>';\r\n";
            }
        }
        
        return FocusList;
    }在上面
 string dataSet = Get_SQL_OnlyRecord("select FocusImg from PS_WebSet where ID = 1"); 
这句读取数据库时有时正确,有时错误。一直找不到原因,请大家帮帮忙!