问题描述
我正在尝试在Visual Studio的C程序中使用OCILIB连接到数据库。我已经使用Nuget软件包安装了OCILIB软件包。
我已经编写了下面的程序来测试我的连接
void err_handler(OCI_Error* err)
{
printf
(
"code : ORA-%05i\n"
"msg : %s\n"
"sql : %s\n",OCI_ErrorGetOCICode(err),OCI_ErrorGetString(err),OCI_GetSql(OCI_ErrorGetStatement(err))
);
}
int main()
{
OCI_Connection* cn;
if (!OCI_Initialize(err_handler,NULL,OCI_ENV_DEFAULT))
{
printf("OCI Initialzation issue");
return 1;
}
printf("trying to create connection\n");
cn = OCI_ConnectionCreate("localhost:1521/xe","aravind",OCI_SESSION_DEFAULT);
if (cn)
{
printf("connected!!");
}
else
{
OCI_Error* err = OCI_GetLastError();
printf("errcode <%hi>,errmsg <%s>\n",OCI_ErrorGetString(err));
printf("NOT connected!!");
}
return 0;
}
错误处理程序输出:
code : ORA-00000
msg : E
sql : (null)
OCI Initialzation issue
我尝试了以下所有连接类型,但没有运气
cn = OCI_ConnectionCreate("<ip>:1521/xe",OCI_SESSION_DEFAULT);
cn = OCI_ConnectionCreate("<full connection string from tnsnames>",OCI_SESSION_DEFAULT);
有人可以帮我吗?
解决方法
为OCI_Initialize()提供错误处理程序。 它将由OCILIB调用,错误详细信息将由OCI_ErrorGetString()返回。