Click here to Skip to main content
14,975,556 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys
I connect to microsoft sql server using this code:
C++
wchar_t * sConStr = L"Driver={SQL SERVER};Server=MyServer;DataBase=MyDB;UID=;PWD=;";
wchar_t wszOutStr[256];
SQLRETURN retcode;
retcode = SQLDriverConnectW(m_hdbc, hWndMain, sConStr, wcslen(sConStr),
		wszOutStr, countof(wszOutStr), &uOutLen,
		SQL_DRIVER_NOPROMPT
		);
The connection takes two long(45 seconds today, 3 seconds yesterday).
I searched google to find proper connection strings, but most found was using odbc DSN, which I don't want to use. I want to connect directly to an existing database.
Can any one show me the right way to connect? any replies appreciated.
I'm new to odbc.
mr.abzadeh

Edit:
I found that I first I must connect to sql server, and then connect to database.
How can I connect in C? google search shows many ado.net results, which I don't want
mr.abzadeh
Posted
Updated 2-Mar-15 10:37am
v2
Comments
PIEBALDconsult 2-Mar-15 16:43pm
   
Dunno, maybe you should try Trusted_Connection=True ?
I have no delay connecting to a local database with:
"DRIVER={SQL SERVER};SERVER=localhost;DATABASE=junk;INTEGRATED_SECURITY=true"
barneyman 2-Mar-15 18:44pm
   
45 seconds sounds like it timed out ... Piebald's connection string is good for SQL, tho' hyou'll have to change the server name

IME ODBC is as fast as OLEDB, even out to Azure, so you shouldn't be experiencing slowness unless your LAN and/or DNS is flakey

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900