简体   繁体   English

SQLConnect() 连接服务器失败

[英]SQLConnect() failed to connect server

I am trying to use SQLConnect() to connect sqlserver with C++:我正在尝试使用 SQLConnect() 将 sqlserver 与 C++ 连接:

 retcode = SQLConnect(hdbc, (UCHAR*)"My server name", 
           strlen((const char*)"My server name"),(UCHAR*)"My ID", 
           strlen((const char*)"My ID"),(UCHAR*)"My PW", 
           strlen((const char*)"My PW"));

but it always return -1 to "retcode" .但它总是return -1 to "retcode" Is there anything wrong with the format of my server name?我的服务器名称格式有问题吗? And how could I set the initial catalog of it?我怎么能设置它的初始目录?

Syntax of SQLConnect is as below SQLConnect 的语法如下

SQLRETURN SQLConnect(
     SQLHDBC        ConnectionHandle,
     SQLCHAR *      ServerName,
     SQLSMALLINT    NameLength1,
     SQLCHAR *      UserName,
     SQLSMALLINT    NameLength2,
     SQLCHAR *      Authentication,
     SQLSMALLINT    NameLength3);

eg:例如:

 retcode=   SQLConnect(hdbc, (SQLCHAR*) "servername", SQL_NTS, (SQLCHAR*) NULL, 0, NULL, 0);

change the example according to your requirement and check根据您的要求更改示例并检查

More informationmsdn更多信息msdn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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