Server Error in '/' Application.
--------------------------------------------------------------------------------

Column 'C' does not belong to table Table.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Column 'gameIsNow' does not belong to table Table.

最近项目上遇到一个很奇怪的问题,查询经常性的出错,这种出错是间歇性的。比如在代码中写select column1 from talbe1。执行完毕后Fill一个DataSet,再访问DataSet中的TableRow以及Column。通常会有一些莫名其妙的错误,例如
    Can not find Table 0.
    Column "column1" dose not belong to Table table.

   
在大多数情况下,没有任何问题,但是程序运行一会儿(不定期),就会出现这个问题。过一会儿可能也好了,但是几十分钟或几个小时后又出现了。
   
经过种种分析、排除,查找原因,最后把问题确定在connection.Close()的上。

SqlConnection.Close Method

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlconnectionclassclosetopic.asp

CAUTION   Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, you should only releaseunmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition. For more information, see Programming for Garbage Collection.

根据这个文章,我们注释了log(日志记录)处的Finalize中的connection的close方法。问题得以解决,但是其原理百思不得其解。


开发经验:
      上面那个问题因挠我们开发人员好久了,后来发现是.net版本没对上号造成系统不兼容,老是说某字段不属于某个表,然后造成整个网站报错,访问不了。

      后来在程序中设置了各种跟踪,发现数据库返回的数据都是正常,该要的字段及其数据都查询出来了,但是最终填充到DataSet的时候就会发生间歇式的错误,根本不是数据库返回的数据,报错的时候,跟踪发现DataSet里面竟然是一张表,这张表只有一个名为Column1的字段,表的记录只有一行,且数据为1。吐血啊,怎么会这样子呢。

      想啊想,找啊找,发现服务器上用的是.net2.0框架,但是我们发布的时候是以vs2008中的.net3.5版本发布,没办法,最后把发布设置改成.net2.0的,上述问题也得到了相应的解决;
      不过有点纳闷的是,服务器上明明升级到了.net 3.5,为什么在IIS的配置中就是找不到相应的3.5的版本号,如下图所示:


 

 

posted on 2009-05-31 15:36  钱途无梁  阅读(2957)  评论(2编辑  收藏  举报