tags:

views:

999

answers:

3
+1  A: 

To specify a default driver, use DRIVER= in the connection string:

DRIVER=driver name here;DATABASE=mydb;USER=foo;PASSWORD=bar

The driver name is the name that appears in the Control Panel ODBC config tool for each driver. Note you will need to supply the info which would normally come from the DSN, in this case the database name.

anon
Thanks, but to me, that isn't a "default" driver, that's a "user specified" driver.
crb
+1  A: 

You can achieve what you want by appending ";SERVER=dbserver" to your connection string.

There is already a server specified in your DSN, but the SERVER keyword in your connectionstring will override that.

http://msdn.microsoft.com/en-us/library/ms715433(VS.85).aspx

Erik E
Handy, but I can't change the connection string that much, just change how it is generated. Eventually I hope we'll rewrite that app to use DSN-less connection strings :)
crb
A: 

Use a DSN-less connection string...it can be created 'on the fly' to exactly suite your purposes....no piddling with odbcad32.cpl or reg/ini files to control/configure a dsn required.

see http://support.microsoft.com/kb/147875

for details

CMB
Thanks, but that doesn't clear up my question about a default driver. The connection string is generated by code I can't change.
crb
Sorry, I misunderstood. To clarify, I have a couple of followup questions.Are you are using ADO to connect with an ODBC targeted database? Is this target Database always SQL Server? Always connected via Native Client? Your desire is to know how to specify the default driver in the OLEDB connect string and not the ODBC DSN? So in essense, you desire to use ADO, specify an OLEDB provider of ODBC, provide additional information in the OLEDB Connection string to specify the SQLServer Target?
CMB
In this case, it's always yes. But I can't change the generated connection string, else I would just put SERVER=dbserver in it.
crb