Connect programmatically using Delphi problem

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
John Whitehead
Posts: 2
Joined: Mon 12 Jan 2009 11:31

Connect programmatically using Delphi problem

Post by John Whitehead » Mon 12 Jan 2009 12:15

I am currently evaluating the SQL Server DBExpress drivers on Delphi before ordering.
I have encountered a problem when trying to programmatically connect to SQL Server Express 2005 during runtime. These are the steps I take:

1. Put a TSQLConnection component (SQLConnection1) on the form.

2. In design-time set the property DriverName to 'DevartSQLServer'. This also automatically sets the following properties:

GetDriverFunc = 'getSQLDriverSQLServer'
LibraryName = 'dbexpsda40.dll'
VendorLib = 'sqloledb.dll'

3. Put a button on the form, on the OnClick event write the following code:

SQLConnection1.Params.Add('HostName=\SQLEXPRESS');
SQLConnection1.Params.Add('DataBase=AdventureWorks');
SQLConnection1.Connected := True;

4. Compile and run the program. Click on the button and the error message 'Connection name missing.' is displayed.

If the parameters in Step 3 are done during design-time, I can connect without a problem. The steps are:

Steps 1 and 2 as above.

3. In design-time click on the property Params and set the following attributes:

Key Value
----------------------------------------
HostName \SQLEXPRESS
DataBase AdventureWorks

4. Put a button on the form, on the OnClick event write the following code:

SQLConnection1.Connected := True;

5. Compile and run the program. Click on the button and a connection will be made.

My development environment is:

Windows Vista Ultimate
Delphi 2007 Professional
Installed trial SQL Server DBExpress drivers
SQL Server Express 2005 installed on a Windows XP machine

Can the connection be made programmatically (if so, how?) or is this just a restriction because of the trial driver?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 12 Jan 2009 16:06

The point is that the HostName and DataBase parameters already exist in the parameters list and you add new parameters with the same names.
To solve the problem you should set parameters values using the Values property, like this:

Code: Select all

SQLConnection1.Params.Values['HostName'] := '\SQLEXPRESS';
SQLConnection1.Params.Values['DataBase'] := 'AdventureWorks';

John Whitehead
Posts: 2
Joined: Mon 12 Jan 2009 11:31

Post by John Whitehead » Mon 12 Jan 2009 16:45

Thanks for the quick solution. Silly me really :D

Post Reply