我正在使用 C++ ODBC 连接到本地 SQL Server。
一旦我尝试连接到服务器;有没有办法验证连接确实成功?
这是我的代码示例,它委托连接句柄并建立连接:
//Allocate the pre-connection handles
this->sReturn = SQL_SUCCESS;
this->sReturn = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &this->eHandle);
this->sReturn = SQLSetEnvAttr(this->eHandle, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC3_80), 4);
SQLAllocHandle(SQL_HANDLE_DBC, this->eHandle, &this->cHandle);
//Connect to the database
this->sReturn = SQLConnect(this->cHandle, reinterpret_cast<SQLWCHAR*>(serverName), SQL_NTS, NULL, 0, NULL, 0);