#define _AFXDLL
#include <afxdb.h>
#include <iostream>
using namespace std;
bool InitHandle(SQLHENV &henv, SQLHDBC &hdbc, SQLHSTMT &hstmt){
int errLineNum = 0 ;
SQLCHAR outstr[1024]="";
short BRWS_LEN=1024, cbConnStrOut;
CString sql;
//获取连接信息
CString DbName="MyDB";
CString IpVal = "localhost,1433";
CString connStr;
connStr.Format("Provider={%s}; DSN=MyDB; DBCName=%s;Database=%s;Uid=zhangsan;Pwd=123465; ","MS", IpVal, DbName);
// Allocate enviroment handle
SQLRETURN retcode = -1;
retcode= SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
if(retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO){
cout << "SQLAllocHandle Error for henv!";
return false;
}
retcode= SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
if(retcode != SQL_SUCCESS && r
Windows下C++连接SQL Server数据库
最新推荐文章于 2024-05-26 21:18:18 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)