Set DateFormat mdy

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Sefidpoor
Posts: 1
Joined: Thu 29 Dec 2016 16:05

Set DateFormat mdy

Post by Sefidpoor » Thu 29 Dec 2016 16:10

Hello,

I am doing something like following, but in this part I want to set the DATEFORMAT to mdy at this level, because I do not want to send it for each connection I open, Is there any way to set it at this level?

Thanks,
Ali

MSCon:=TMSConnection.Create(nil);
if sPayUsername='' then
MSCon.Authentication:=auWindows else
MSCon.Authentication:=auServer;
MSCon.Server:=sPayServer;
MSCon.DataBase:=sPayDatabase;
MSCon.UserName:=sPayUsername;
MSCon.Password:=sPayPassword;
MSCon.ConnectionTimeout:=iPayTimeoutConnect;
MSCon.Options.DefaultLockTimeout:=iPayTimeoutCommand*1000;
CommandTimeout:=iPayTimeoutCommand;
Connection:=MSCon;

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

Re: Set DateFormat mdy

Post by azyk » Fri 30 Dec 2016 09:36

In SDAC there is no separate option to specify a value for DATEFORMAT. To solve the described task you can use the solution proposed below or any other.

You can create a handler for the TMSConnection.AfterConnect event, in which a value for DATEFORMAT will be set, for example using the TMSConnection.ExecSQL method. An example of this code can look like this:

Code: Select all

type
  TMainForm = class(TForm)
    ...
    procedure AfterConnect_SET_DATEFORMAT_mdy(Sender: TObject);
    ...
  end;
...
procedure TMainForm.AfterConnect_SET_DATEFORMAT_mdy(Sender: TObject);
begin
  TMSConnection(Sender).ExecSQL('SET DATEFORMAT mdy;');
end;
When creating the TMSConnection instance assign it the above handler:

Code: Select all

MSCon:=TMSConnection.Create(nil);
...
MSCon.AfterConnect := AfterConnect_SET_DATEFORMAT_mdy;
Connection:=MSCon;

Post Reply