写了一个小小程序,用来上课,主要应用是学生可以看到老师发布的一些内容。

在使用了一个分页程序后(SQL的双TOP法),发现前台和后台的两个页(这两个页都是查询同一个视图,该视图里有两表)打开时经常会提示错误(错误信息和代码在下面),但刷新页面后,错误就消失,显示我想要的内容。在使用同样的分页程序(也就是下面的CreatePagingSql)在其他页(查询其他表或者视图)却从不会出现这样的错误。

编辑环境是:Win7 64位 双核。VS2010,Net FrameWork4。

服务器环境是:Win2003 32位 单核,Net FrameWork4。

我测试过,如果将该程序不经发布、编译,直接放源代码到服务器使用,程序是没有什么提示错误的;但如果发布了之后(从编辑环境发布到服务器),就经常会出现这样的错误。

我在想,会不会是我发布的环境跟服务器的环境差别太大,所以才会出现这样的错误呢?于是我在服务器上又安装了VS2010,但结果还是一样,发布了之后还是会提示错误。

发生的错误信息如上:

System.Exception: 数据查询失败!ExecuteTable查询语句为: SELECT TOP 20 * FROM (select * from [topicview] where t_id>0) AS T ORDER BY t_addtime desc |a=da|Open ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i) at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values) at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values) at System.Data.ProviderBase.SchemaMapping.LoadDataRow() at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at OLC.DAL.Database.ExecuteTable(CommandType cmdType, String cmdText, SqlParameter[] commandParameters) --- End of inner exception stack trace --- at OLC.DAL.Database.ExecuteTable(CommandType cmdType, String cmdText, SqlParameter[] commandParameters) at OLC.BLL.topic.GetTopicList(String strWhere, String filedOrder, Int32 pageSize, Int32 pageIndex, Int32& totolCount) at admin_admin_art_list.BindRepeater(String _strWhere, String _strOrderBy) at admin_admin_art_list.Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)。

发生错误页的代码如下:

ExcuteTable

        /// <summary>
        /// 获得一个表名为result数据表
        /// </summary>
        /// <param name="cmdType">CommandType枚举</param>
        /// <param name="cmdText">命令字符串</param>
        /// <param name="commandParameters">命令参数</param>
        /// <returns>一个表名为Result的DataTable </returns>
        public DataTable ExecuteTable(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            string a = string.Empty;
            DataTable result = new DataTable();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandTimeout = 60;
                PrepareCommand(cmd,cmdType, cmdText, commandParameters);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                a = "da|"+cmd.Connection.State;
                da.Fill(result);
                a = "fill";
            }
            catch (Exception ex)
            {
                throw new Exception("数据查询失败!ExecuteTable查询语句为:" + cmdText+"|a="+a, ex);
            }
            return result;
        }
View Code

相关文章:

  • 2022-12-23
  • 2022-01-29
  • 2021-10-16
  • 2022-12-23
  • 2022-01-14
  • 2022-02-15
  • 2021-05-29
  • 2021-11-17
猜你喜欢
  • 2022-01-31
  • 2021-09-18
  • 2021-11-05
  • 2021-11-17
  • 2021-10-14
  • 2021-06-27
相关资源
相似解决方案