简体   繁体   中英

sqldriverconnect in c++ failed to connect to local database sql 2008

can someone here kindly help? I am trying to connect to sql server 2008 in c++ by using SqlDriverConnect. Here is my code:

SQLTCHAR *srv = (SQLTCHAR *) "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=bbData;Data Source=NBK-EMMAY";
SQLRETURN rc = SQLDriverConnect(hdbc, NULL, srv, strlen((char*)srv),
                                (SQLWCHAR*)OutConnStr, 255, &OutConnStrLen, SQL_DRIVER_PROMPT);

Note, the srv string is created and verified by the .udl file. I have tried various options, but seems I can go nowhere. Many thanks in advance!

You using an OleDb connection string, not an ODBC connection string. SqlDriverConnect in an ODBC function, it won't work with an OleDb provider.

Try using the following connection string:

Driver={SQL Server Native Client 10.0};Server=JBK-EMMAY;Database=bbData;Trusted_Connection=yes;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM