[英]Reading a Date field from Pervasive database causes crash
I am trying to read some data from a Pervasive database (through a C# Console app I wrote) and whenever I reach a row that contains information on a particular date column, the program throws an exception. 我试图(通过我编写的C#控制台应用程序)从Pervasive数据库中读取一些数据,并且每当到达包含特定日期列信息的行时,程序都会引发异常。
I managed to identify the problematic records: 我设法找出有问题的记录:
DtTransDate DtSystemTime DtnLotteryDrawDate
7/15/2013 3:01:32 AM 9/1/8226
As you can see, the DtnLotteryDrawDate is a weird value but I should be able to read it as it is a valid date. 如您所见,DtnLotteryDrawDate是一个怪异的值,但是我应该能够读取它,因为它是有效日期。 I am using the ADO.NET Provider for Pervasive (which by the way, indicates that there's a bug on the Pervasive driver itself):
我正在使用Pervasive的ADO.NET提供程序(顺便说一句,它表明Pervasive驱动程序本身存在错误):
at Pervasive.Data.SqlClient.Lna.e.ak(u )
at Pervasive.Data.SqlClient.Lna.w.a(Int16 , Int32 , ad , f )
at Pervasive.Data.SqlClient.Lna.e.aa(Int32 , Boolean )
at Pervasive.Data.SqlClient.PsqlDataReader.e()
at Pervasive.Data.SqlClient.PsqlDataReader.Read()
So I tried the ODBC Driver and got the same problem but a tiny better message: 因此,我尝试了ODBC驱动程序,并得到了相同的问题,但有一条更好的消息:
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
at Pervasive.Data.SqlClient.Lna.u.r()
at Pervasive.Data.SqlClient.Lna.aq.a(u )
at Pervasive.Data.SqlClient.Lna.e.ak(u )
at Pervasive.Data.SqlClient.Lna.w.a(Int16 , Int32 , ad , f )
at Pervasive.Data.SqlClient.Lna.e.aa(Int32 , Boolean )
at Pervasive.Data.SqlClient.PsqlDataReader.e()
at Pervasive.Data.SqlClient.PsqlDataReader.Read()
So I tried converting the Date to a string to see if that would get rid of the issue but that didn't work. 因此,我尝试将Date转换为字符串,以查看是否可以解决此问题,但无法正常工作。 Basically, I wrote the following SQL statement:
基本上,我编写了以下SQL语句:
SELECT DtTransDate ,
TmSystemTime ,
CONVERT(DtnLotteryDrawDate, SQL_CHAR) as DtnLotteryDrawDate
FROM TICKHISH
WHERE ( DtTransDate >= { d '2013-07-15' }
The above SQL Statement would throw the following exception: 上面的SQL语句将引发以下异常:
error in row
and the stack trace I pasted above. error in row
和我上面粘贴的堆栈跟踪error in row
。
If I DO NOT try to convert the field to string, then the Exception is more helpful: 如果我不尝试将字段转换为字符串,则异常更为有用:
Year, Month, and Day parameters describe an un-representable DateTime.
So essentially, the ADO.NET driver is trying to construct a Date passing in incorrect values for either the month or the day. 因此,从本质上讲,ADO.NET驱动程序试图构造一个日期,该日期传递的月份或日期的值不正确。 Probably is passing the
8226
as either the day or the month field. 可能是通过
8226
作为日或月字段。
I tried running the same SQL statement on the Pervasive Control Panel (PCC) and interestingly, the PCC program doesn't crash if I do not attempt to convert to string the date field but if I try any kind of conversion or calling a function like year(DtnLotteryDrawDate)
immediately crashes as well. 我尝试在普及控制面板(PCC)上运行相同的SQL语句,有趣的是,如果我不尝试将日期字段转换为字符串,但是尝试任何类型的转换或调用类似函数,则PCC程序不会崩溃
year(DtnLotteryDrawDate)
立即崩溃。
Any ideas on how to work around this issue? 关于如何解决此问题的任何想法?
TINY UPDATE 微小更新
I was able to set up a Linked Server using SSMS and connect to the Pervasive database through the linked server. 我能够使用SSMS设置链接服务器,并通过链接服务器连接到Pervasive数据库。 When I attempt to run this simple query:
当我尝试运行此简单查询时:
SELECT * FROM OPENQUERY(linked_server, 'SELECT * FROM MyTable where DtTransDate = ''2013-07-15'' ')
I get this error: 我收到此错误:
OLE DB provider "MSDASQL" for linked server "linked_server" returned message "[Pervasive][ODBC Client Interface]Data truncated column 186.".
OLE DB provider "MSDASQL" for linked server "linked_server" returned message "[Pervasive][ODBC Client Interface]Invalid date, time or timestamp value.".
Msg 7330, Level 16, State 2, Line 3
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "linked_server".
There seems to be something wrong with the actual data. 实际数据似乎有问题。 I was able to insert, through the PCC, and view through both PCC and the ADO.NET provider a data value of 9/1/8226.
我能够通过PCC插入,并通过PCC和ADO.NET提供程序查看9/1/8226的数据值。 If I changed the bytes of the date value through Function Executor to make the date appear invalid, I was able to get an "error in row" type message.
如果我通过Function Executor更改了日期值的字节以使日期显得无效,那么我将收到“错误提示”类型的消息。 There used to be a couple of programs that could fix invalid dates but I think one was pulled.
曾经有一些程序可以修复无效的日期,但我认为其中一个已被取消。 The other is FixDates from Goldstar Software, but it is not free.
另一个是Goldstar Software的FixDates,但它不是免费的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.