I'm using the MFC class CDatabase. To establish a connection to SQL Server, I'm calling OpenEx() with a connection string. My problem is that the object seems unable to interpret the DSN part of the string. The connection string looks like this:
ODBC;DSN=mySystemDSN;UID=myUsername;WSID=myMachineName;DATABASE=myDatabaseName;Trusted_Connection=Yes
That ought to be right because I got it by using OpenEx( NULL ), choosing the data source manually and then calling GetConnect().
But this string doesn't seem to contain enough information: OpenEx() always pops up a dialogue asking for more. It doesn't seem to matter what I choose from this dialogue - I can pick a DSN associated with a completely different database and things still work (a call to GetConnect() in that situation shows that it's using my connection string except for the DSN part, which is borrowed from the other data source).
I need my application to be able to connect to the database automatically - dialogue boxes are a deal-breaker. I've tried a DSN-less connection with similar results. What's going on here, and what can I do about it?
edit in answer to Neil Butterworth's question:
The information I provided when I created the DSN in the ODBC Data Source Administrator was as follows:
driver: SQL Server
name: mySystemDSN
server: myMachineName
authentication type (can be Windows or SQL Server): Windows
checkbox "Connect to SQL Server to obtain default settings for the additional configuration options.": ticked
checkbox "Change the default database to": ticked and myDatabaseName chosen from drop-down menu
checkbox "Use ANSI quoted identifiers": ticked
checkbox "Use ANSI nulls, paddings and warnings": ticked
checkbox "Perform translation for character data": ticked