Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Service App where to Create and Init The DataBase


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0 Threads: [ Previous | Next ]
Donald Bossen

Posts: 81
Registered: 2/3/02
Service App where to Create and Init The DataBase  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 22, 2016 8:30 AM
I have written a service that connects to a sql service and tables. My service Start is

procedure TSerUploadFedex.ServiceStart(Sender: TService; var Started: Boolean);
var
x,y : longInt;
begin
with FrmTb2 Do
begin
Delay := ReadIniInt(IniCfg,'Timer','Delay');
UpTimer.Interval := Delay * 1000;
end;
end;

It starts a TTimer that Initlizes the Database and tables each time though the timer. Here is the abivated code

procedure TSerUploadFedex.UpTimerTimer(Sender: TObject);
var
ConnectionFedexData : TADOConnection;
TblPkg : TADODataSet;
TblPkgT : TADODataSet;
begin
UpTimer.Enabled := False;

ConnectionActivant := TADOConnection.Create(Self);
ConnectionActivant.ConnectionString := '';
ConnectionActivant.LoginPrompt := False;
ConnectionActivant.KeepConnection := True;
ConnectionActivant.CommandTimeout := 0;

TblCarr := TADODataSet.Create(Self);
TblCarr.Connection := ConnectionActivant;
TblCarr.CommandTimeout := 0;
TblCarr.CursorType := ctStatic;
TblCarr.CursorLocation := clUseClient;
TblCarr.LockType := ltReadOnly;

TblClip := TADODataSet.Create(Self);
TblClip.Connection := ConnectionActivant;
TblClip.CommandTimeout := 0;
TblClip.CursorType := ctKeyset;
TblClip.CursorLocation := clUseServer;
TblClip.LockType := ltOptimistic;

TblPick := TADODataSet.Create(Self);
TblPick.Connection := ConnectionActivant;
TblPick.CommandTimeout := 0;
TblPick.CursorType := ctStatic;
TblPick.CursorLocation := clUseClient;
TblPick.LockType := ltOptimistic;

ConnectionJBI := TADOConnection.Create(Self);
ConnectionJBI.ConnectionString := '';
ConnectionJBI.LoginPrompt := False;
ConnectionJBI.KeepConnection := True;
ConnectionJBI.CommandTimeout := 0;

TblRank := TADODataSet.Create(Self);
TblRank.Connection := ConnectionJBI;
TblRank.CommandTimeout := 0;
TblRank.CursorType := ctStatic;
TblRank.CursorLocation := clUseClient;
TblRank.LockType := ltReadOnly;

TblUser := TADODataSet.Create(Self);
TblUser.Connection := ConnectionJBI;
TblUser.CommandTimeout := 0;
TblUser.CursorType := ctStatic;
TblUser.CursorLocation := clUseClient;
TblUser.LockType := ltReadOnly;

TblUps := TADODataSet.Create(Self);
TblUps.Connection := ConnectionJBI;
TblUps.CommandTimeout := 0;
TblUps.CursorType := ctStatic;
TblUps.CursorLocation := clUseClient;
TblUps.LockType := ltOptimistic;

if ConnectToSql(Msg) then
begin
ConnectionFedexData := TADOConnection.Create(Self);
ConnectionFedexData.ConnectionString := BuidConnectionString;//Builds the Connection String
ConnectionFedexData.LoginPrompt := False;
ConnectionFedexData.KeepConnection := True;
ConnectionFedexData.CommandTimeout := 0;
ConnectionFedexData.ConnectionTimeout := 0;
ConnectionFedexData.DefaultDatabase := 'Fedex';
ConnectionFedexData.Connected := True;

TblPkg := TADODataSet.Create(Self);
TblPkg.Connection := ConnectionFedexData;
TblPkg.CommandTimeout := 0;
TblPkg.CursorType := ctStatic;
TblPkg.CursorLocation := clUseClient;
TblPkg.LockType := ltOptimistic;

TblPkgT := TADODataSet.Create(Self);
TblPkgT.Connection := ConnectionFedexData;
TblPkgT.CommandTimeout := 0;
TblPkgT.CursorType := ctStatic;
TblPkgT.CursorLocation := clUseClient;
TblPkgT.LockType := ltOptimistic;
//Process Data
ConnectionActivant.Free;
ConnectionJBI.Free;
ConnectionFedexData.Free;
TblCarr.Free;
TblPick.Free;
TblClip.Free;
TblPkg.Free;
TblPkgT.Free;
TblRank.Free;
TblUser.Free;
TblUps.Free;
end; //ConnectToSql
UpTimer.Enabled := True;
end;

I tried moving the Connection code to the ServiceStart event but the Service would not start (Could not debug the start up code so had no idea why it would not start). Where besides where it is should the start Init startup code be moved.

Thanks in advance
Donald S Bossen
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02