我尝试使用VC ++ MFC(Visual Studio 2012)连接oracle XE(11.2.0.2.0)数据库。下面是oracle网站上给出的示例代码。
void CMFCOracleOCCIDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
const string userName = "<username>";
const string password = "<password>";
const string connectString = "";
Environment *env = Environment::createEnvironment();
{
Connection *conn = env->createConnection(userName, password, connectString);
Statement *stmt = conn->createStatement("SELECT * FROM tab");
ResultSet *rs = stmt->executeQuery();
for(int i=1;i<20;i++){
rs->next();
//Below are the commented 4 lines
/*
string s = rs->getString(1);
CString str2(s.c_str());
lstBox01.AddString(str2);
MessageBox(str2);
*/
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
}
Environment::terminateEnvironment(env);
}
在上面的代码中注释中的4行,它工作正常。否则它仅适用于一个循环(i = 1)并显示正确的消息(仅一次)。之后,得到以下错误
0x51A4CCC8(msvcp110d.dll)的第一次机会异常。选择中断后,它将转到文件xutility和function
inline void _Container_base12::_Orphan_all()
环境:
Windows 8.1(64)
Oracle XE(11.2.0.2.0)
OCCI Library : Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
Download instantclient-sdk-nt-11.2.0.2.0.zip
Visual Studio 2012(调试 - 配置)
修改
在getString()(varchar2字段)的情况下引发此错误。当使用整数字段和getInt()时,它工作正常。