服务与会话
OCI提供OCIServerAttach,OCIServerDetach,OCISessionBegin,OCISessionEnd接口管理服务与会话。
/*
* Connect and create an user session
*/
sword status = 0;
static OCIServer *svrhp = (OCIServer *)0;
OCIHandleAlloc(envhp, (dvoid **)&svrhp, OCI_HTYPE_SERVER, (size_t)0,(dvoid **)0);
status = OCIServerAttach(svrhp, errhp, (text *)dsn, (sb4)strlen((char *)dsn), OCI_DEFAULT);
status = OCISessionBegin(svchp, errhp, sesnhp, OCI_CRED_RDBMS, OCI_DEFAULT);
if (status != OCI_SUCCESS)
{
printf("Connection failed \n");
report_error(errhp);
}else
printf("Connection - Success \n");
OCISessionEnd (svchp, errhp, sesnhp, OCI_DEFAULT );
OCIHandleFree((dvoid *) sesnhp, OCI_HTYPE_SESSION);
sesnhp = NULL;
sword rc = OCIServerDetach(svrhp, errhp, OCI_DEFAULT );
printf("传入正确的参数,结果为:%s\n",getErrStr(rc));