Date Value Not Valid

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
duncanc
Posts: 2
Joined: Thu 25 Aug 2011 23:42

Date Value Not Valid

Post by duncanc » Fri 26 Aug 2011 00:21

Hi,

I have a simple program that goes and retrieves a date value from an SQL Table. On my machine (Win 7 64 bit) it works fine and returns the following:

Returned Str: 15/08/2011
Returned Float: 40770
Returned Formated: 15/08/2011

When I run it on a newly installed (Win 7 32 bit) machine it fails with an Date is not Valid error:

Returned Str: 2011-08-15
Returned Float: Error!
Returned Formated: Error!

Now I can see that the date is not formatted in the correct way but when I check the following details they are both the same.

Date Short: d/MM/yyyy
Date Long: dddd, d MMMM yyyy
Date Separator: /
DefaultLCID = 00000C09
PriLangID = 00000009
SubLangID = 00000003
FarEast = False
MiddleEast = True

Why is the returned date not formated correctly on one computer but is on the other? If I format todays date using the now function all is correct.

Below is the sample code.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;
  {Open Data}
  TVSystemQ.Active := True;
  TVSystemQ.Last;
  {Update Info}
  Memo1.Lines.Add('Date Short: ' + ShortDateFormat);
  Memo1.Lines.Add('Date Long: ' + LongDateFormat);
  Memo1.Lines.Add('Date Separator: ' + DateSeparator);
  Memo1.Lines.Add(Format('DefaultLCID  = %.8x', [SysLocale.DefaultLCID]));
  Memo1.Lines.Add(Format('PriLangID  = %.8x', [SysLocale.PriLangID]));
  Memo1.Lines.Add(Format('SubLangID  = %.8x', [SysLocale.SubLangID]));
  Memo1.Lines.Add(Format('FarEast  = %s', [BoolToStr(SysLocale.FarEast, True)]));
  Memo1.Lines.Add(Format('MiddleEast  = %s', [BoolToStr(SysLocale.MiddleEast, True)]));
  Memo1.Lines.Add('');

  try
    Memo1.Lines.Add('Returned Str: ' + TVSystemQ.FieldByName('Week').AsString);
  except
    Memo1.Lines.Add('Returned Str: Error!');
  end;
  try
    Memo1.Lines.Add('Returned Float: ' + FloatToStr(TVSystemQ.FieldByName('Week').AsFloat));
  except
    Memo1.Lines.Add('Returned Float: Error!');
  end;
  try
    Memo1.Lines.Add('Returned Formated: ' + FormatDateTime('dd/mm/yyyy', TVSystemQ.FieldByName('Week').AsDateTime));
  except
    Memo1.Lines.Add('Returned Formated: Error!');
  end;
  {Close Data}
  TVSystemQ.Active := False;
end;
I have tried it on several other computers and they all work, can anybody try an shed some light on this for me.

I am using Delphi 6 and Delphi 2007 with SDAC Professional Version 5.10.0.8

Thanks
Duncan

AndreyZ

Post by AndreyZ » Tue 30 Aug 2011 14:00

Hello,

Such problem can occur if there is no Native Client provider installed on a computer. When there is no Native Client provider, SDAC uses OLEDB provider. OLEDB provider returns DATE columns in the string format, and this causes the problem. To solve the problem, you should install Native Client provider on the machine where you encountered this problem.

duncanc
Posts: 2
Joined: Thu 25 Aug 2011 23:42

Post by duncanc » Thu 01 Sep 2011 01:18

Thanks very much - Works Perfectly :D

Post Reply