Accessing SQL Server on my web host's server

Your TDatabase parameters are not going to be any different.  Below is some
code from an ISAPI app I am working on.  BTW, develop your app as a regular
delphi program first, then make a DLL out of it.  It's easier to test.

I have a unit with constant values defined.  Below are the constants for my
alias and parameters.

const
     kDBName = 'FastWebDB';
     kDBParams =  'DATABASE NAME=FastWebDB'#$D#$A'USER
NAME=YourUserID'#$D#$A'PASSWORD=YourPassword'#$D#$A +
   'ODBC DSN=FastWebDB'#$D#$A'SQLQRYMODE=SERVER'#$D#$A'SQLPASSTHRU MODE=SHARED
NOAUTOCOMMIT'#$D#$A;

Your queries need to be thread safe, since your DLL could be running in
multiple threads on the server.  The first line of code below calls a create
method that creates a TSession, TDatabase and two TQuerys.

Then to execute a query, I do the second block of code.  The sessionhandler
object follows.

 fHandler := TSessionHandler.Create(kDBName, kDBParams);

 SQLStr := 'SELECT * ' +
     '  FROM Directory ' +
     ' WHERE lParentID = ' + IntToStr(fDirID) +
     ' ORDER BY iType, iSortOrder';
 errStr := fHandler.DoQuery(SQLStr);
 if (errStr = '') then
  with IO.Handler do begin
   while not Query.EOF do begin
    ProcessStateDir(IO, Query);
    Query.Next;
   end;
  end
 else begin
    .
    .
 end;

TSessionHandler = class(TObject)
private
 fSession: TSession;
 fDB: TDatabase;
 fQry: TQuery;
 fQry2: TQuery;
 fOwnsDB: boolean;
 function GetDBName: string;
public
 constructor Create(const aliasStr, parmStr: string); overload;
 constructor Create(const aDB: TDatabase); overload;
 constructor Create(const dbName: string); overload;
 destructor Destroy; override;
 function DoQuery(const aSQL: string): string; overload;
 function DoQuery(const aSQL: string; const NewQuery: Boolean): string;
overload;
 function Execute(const aSQL: string; var numRows: longint): string;

   property DBRef: TDatabase read fDB;
   property DBName: string read GetDBName;
   property Query: TQuery read fQry;
   property Query2: TQuery read fQry2;
end;

constructor TSessionHandler.Create(const aliasStr, parmStr: string);
var
   sName: string;
begin                                      // generate a unique session name
   sName := IntToStr(Sessions.Count + 1) + DateTimeToStr(Now);
   fSession := TSession.Create(nil);       // to be thread-safe, each query
needs...
                                           // ...its own TSession object
   fSession.SessionName := sName;          // Important: Session name is unique

   fSession.KeepConnections := true;
 fSession.Active := true;

 fOwnsDB := true;
 fDB := TDatabase.Create(nil);
 fDB.SessionName := sName;               // Very Important: Assign to unique
Session
 fDB.AliasName := aliasStr; //     + '_Alias';
 fDB.DatabaseName := aliasStr; // + '_DB';
 fDB.KeepConnection := true;
 fDB.LoginPrompt := false;
 fDB.Params.Text := parmStr;             // Important: Params holds user ID &
Password
 fDB.Connected := true;                  // Important: Connect after everything
else

 fQry := TQuery.Create(nil);
 fQry.SessionName := sName;              // Very Important: Assign to unique
Session
 fQry.DatabaseName := fDB.DatabaseName;
 fQry.RequestLive := false;
 fQry.UniDirectional := true;

 fQry2 := TQuery.Create(nil);
 fQry2.SessionName := sName;              // Very Important: Assign to unique
Session
 fQry2.DatabaseName := fDB.DatabaseName;
 fQry2.RequestLive := false;
 fQry2.UniDirectional := true;
end;

function TSessionHandler.DoQuery(const aSQL: string): string;
begin
 Result := '';
 try
   fQry.SQL.Clear;
   fQry.SQL.Add(aSql);
   fQry.Open;
 except
   on E: Exception do begin
     Result := TSQLBase.ErrorReportString(E);
  end;
 end;
end;

Quote
Lee Grey wrote:
> I finally bit the bullet and signed up with a real web host.  I'm on an NT
> server that offers ODBC/DSN for Access, dBase, Paradox, and SQL Server,
> among others.

> That's great, but I'm kind of lost.  I can create an ODBC/DSN via my
> administration page on the web host, but I'm not sure how to write a Delphi
> web server app (CGI or ISAPI) to actually access it.  How do I set up the
> TDatabase component to find that ODBC/DSN?

> If I'm asking stupid questions, please forgive me.  I'm very new to this
> area.

> Thanks,
> Lee Grey

> ____________________________________
> Free software for stock and options traders at
> http://www.optioninsight.com.  Users are very
> impressed -- read the User Feedback page.
>                  ---------------------------
> Get paid to surf the web!  Better yet,
> get paid when others surf the web, too!
> http://alladvantage.com/go.asp?refid=AQP602