Ramblings

Delphi Programming Observations

Tuesday, November 4, 2008

ADO to dbExpress, first steps

At work, we use ADO exclusively to connect to MS SQL Server, and I’m interested in exploring some of the things you can do with dbExpress and metadata, so I am trying to figure out how to create a connection on the fly, without setting up a new connection through Delphi, to be stored in the dbx ini files. I recently read a newsgroup post about deployment problems with Delphi 2009 needing dbxconnections.ini and dbxdrivers.ini, but I think eventually, it will be fixed.

So, drop a TSQLConnection and a TSQLQuery on a form, set SQLQuery1.SQLConnection to SQLConnection1.

To connect to the database:

uses
   DbxMsSql; // required to register the driver

SQLConnection1.DriverName := 'MSSQL';

SQLConnection1.Params.Values['hostname'] :=
   'HostName\SQLExpress'; // instance name
SQLConnection1.Params.Values['database'] :=
   'databasename';
SQLConnection1.Params.Values['os authentication'] :=
   'True'; // if you want Windows Authentication

SQLConnection1.Connected := true;

then the SQLQuery1 can be used very similarly to a TADOQuery

posted by Jason at 12:12 am  

Comments are closed.