Connect to MSSQL Server without setting up ODBC Data Source
-
I'm working on a database project that will ultimately interface with an MS SQL Server 2008 R2 server over a large network. For development, I have MS SQL 2008 R2 Express running on a server in my lab with the IP Address 192.168.16.103.
If I create an ODBC Data Entry in control panel, I can connect to the remote database without problem. Example:
@
db->setDatabaseName( "Server=JOSHUA\SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;" );
db->setUserName( "tbj" );
db->setPassword( "..." );
db->setHostName( "" );
@
However, if I try to just connect directly to the database using an IP Address:
@
db->setDatabaseName(
"Data Source=192.168.16.103,1433;Network Library=DBMSSOCN;"
);db->setDatabaseName( "sqlexpress" );
db->setUserName( "tbj" );
db->setPassword( "..." );
db->setHostName( "" );@
Then, I get the error message:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect.It would seen that, no matter what I do, the QODBC driver attempts to connect via a registered data source. Is there any way to avoid this? I was hoping to connect to the database directly, as I would a PostgreSQL database.
Any advice is greatly appreciated.
Thanks!
Tom -
After much research and reading, the answer to this question appears to be an emphatic no. This is disappointing, considering how easily the Microsoft native client makes connecting to a remote data source. The functionality is there; Qt simply isn't bothering to add this feature.
The solution I'm going to use for my software is to put a button in the settings dialog that opens the ODBC data connection dialog. On a 64-bit system, one would open:
c:\windows\sysWOW64\odbcad32.exe
-
I know its an older post, but the reply is just wrong, if someone else wants to connect, here is the connection string to use:
@db->setDatabaseName("Driver={SQL Server Native Client 11.0};Server=<ip/host>;Database=<database>;Uid=<userid>;Pwd=<password>;")@
More info on dsn less connections can be found here:
"Connection Strings":http://www.connectionstrings.com/