在ODBC中为sqlconnectw函数指定DSN名称 [英] Specifying DSN names for the sqlconnectw function in ODBC
问题描述
以下是编译和工作:
rc = SQLConnect(ConHandle,(SQLWCHAR *)dailyworkbook,SQL_NTS,NULL,SQL_NTS,NULL,SQL_NTS);
以下是编译,但我得到了运行时访问冲突:
c = SQLConnect(ConHandle,(SQLWCHAR *)Ldailyworkbook,SQL_NTS,NULL,SQL_NTS, NULL,SQL_NTS);
我很困惑。任何见解都会有所帮助。
我尝试过:
在线帮助页面。 Visual Studio中的调试。
The following is compiling and working:
rc = SQLConnect(ConHandle, (SQLWCHAR*)"dailyworkbook", SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
The following is compiling but I get a run time access violation:
c = SQLConnect(ConHandle, (SQLWCHAR*)L"dailyworkbook", SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
I am puzzled. Any insight would be helpful.
What I have tried:
Online help pages. Debugging in Visual studio.
推荐答案
我不确定为什么会发生访问冲突,但可能是由于UserName
和身份验证
参数。当这些是NULL
时,您还应传递零而不是SQL_NTS
的长度:
I don't know for sure why the access violation occurs but it is probably due to theUserName
andAuthentication
parameters. When those areNULL
, you should also pass zero instead ofSQL_NTS
for the length:
c = SQLConnect(ConHandle, (SQLWCHAR*)L"dailyworkbook", SQL_NTS, NULL, 0, NULL, 0);
或通过空字符串,可以使用 SQL_NTS
或零
or pass empty strings which may use SQL_NTS
or zero
c = SQLConnect(ConHandle, (SQLWCHAR*)L"dailyworkbook", SQL_NTS, (SQLWCHAR*)L"", SQL_NTS, (SQLWCHAR*)L"", SQL_NTS);
如果必须使用char或宽字符串取决于您的项目设置。以上假设您有一个Unicode项目。
我也只能猜到为什么你没有通过第一次调用获得访问冲突,但我认为这是一个潜力解释:
当使用Unicode构建并传递char字符串时,连接将失败,因为在使用其他参数之前无法找到服务器并且函数返回。
If you have to use char or wide strings depends on your project settings. The above assumes that you have a Unicode project.
I can also only guess why you did not get the access violation with the first call but I think this is a potential explanation:
When having a Unicode build and passing a char string, the connect will fail because the server can not be found and the function returns before using the additional parameters.
这篇关于在ODBC中为sqlconnectw函数指定DSN名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!