MS SQL Server and DateTime

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
XStranger
Posts: 8
Joined: Wed 04 Mar 2015 13:55

MS SQL Server and DateTime

Post by XStranger » Tue 08 Sep 2015 08:43

Hi,

I use UniDAC for working with FireBird 2.5 and MS SQL Server 2012 at one application.
When I get DateTime value, I have exception EConvertError:

Code: Select all

MyDataSet.DataSet.FieldByName('DTBEGIN').AsDateTime
or
UniQuery1.FieldByName('DTBEGIN').AsDateTime
But if I use line

Code: Select all

MyDataSet.DataSet.FieldByName('DTBEGIN').AsVariant
or
DateTimeToStr(VarToDateTime(MyDataSet.DataSet.FieldByName('DTBEGIN').AsVariant))
all ok!

Error create because format in MS SQL Server is 'YYYY-MM-DD'.
Please make support DateTime for MS SQL Server.

P.S. Sorry for my bad English. Can I write in Russian at next?

Best regards, Alexander.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: MS SQL Server and DateTime

Post by azyk » Tue 08 Sep 2015 13:59

Unfortunately, we couldn't reproduce the problem. Such error may occur if the datetime2 type is used on the SQL Server, and the standard OLEDB provider is used for connection to the server. The point is that the standard OLEDB provider processes datetime2 fields as string fields. In such case, to solve the problem, try using the SQL Native Client provider. For this, in connection settings, set the option TUniConnection.SpecificOptions.Values['OLEDBProvider'] to 'prNativeClient'.

You can write us in Russian on the forum for Russian-speaking users:
http://forums.devart.com/ru/viewforum.php?f=26

Post Reply