C语言连接SqlServer2000,连接失败。。。,提示Connect failed.,请问哪边出错了?求高手指点
#include <stdio.h> #include <string.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <odbcss.h>
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
int main() {
RETCODE retcode;
UCHAR szDSN[20] = "coordinates ", //数据源名
szUID[3] = "sa ", //id
szAuthStr[3]= "sa "; //paswd
UCHAR sql1[30] = "select x1 from zuobiao";
// Allocate the ODBC Environment and save handle.
retcode = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);
// Notify ODBC that this is an ODBC 3.0 application.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,SQL_IS_INTEGER);
// Allocate an ODBC connection handle and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLConnect(hdbc1, szDSN, 4, szUID, 2, szAuthStr, 0);
if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
{
printf("Connect failed.");
}
else {
// Connects to SQL Server always return
// informational messages. These messages can be
// retrieved by calling SQLGetDiagRec.
SQLExecDirect (hstmt1,sql1,30) ;
//char list[18];
//SQLBindCol(hstmt1, 1, SQL_C_CHAR, list, 18, 0);
SQLFetch(hstmt1);
printf("%s\n",sql1);
}
// Allocate statement handles and do ODBC processing.
/* Clean up. */
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return(0);
}