Search code examples
sqldelphiodbcdbexpress

TSQLConnection to a user chosen DSN at runtime


I want to use dbExpress and a TSQLConnection object to allow the user of my application to connect to any of their ODBC dsn and run a SQL query against it.

I have it so the user can select a DSN, (by DSN i mean all the configured data sources listed in control panel - administrative tools - Data Sources (ODBC)), but once they have selected one I am not sure how to configure the TSQLConnection object.

I think I need to set :

SQLCon.connectionName

SQLCon.driverName

SQLCon.getDriverFunc

In the registry settings for a given DSN I have a 'DRIVER' entry that points to a DLL but nothing to indicate the 'getDriverFunc' value.

Does anyone have any advice or an example of setting up a TSQLConnection (or any other delphi db connection) to an ODBC DSN at runtime ?

Thanks


Solution

  • I have found that the best way to do it is to use a TADOConnection and simply specify the DSN in the connection string.