Oracle常用的OCI函数之三
【IT168 服务器学院】4.连接/断开服务器
多用户方式连接:
sword OCIServerAttach(
OCIServer *srvhp,//未初始化的服务器句柄
OCIError *errhp,
CONST text *dblink,//服务器SID
sb4 dblink_len,
ub4 mode //=OCI_DEFAULT,系统环境将设为阻塞方式
);
sword OCIServerDetach (
OCIServer *srvhp,
OCIError *errhp,
ub4 mode //OCI_DEFAULT
);
单用户方式连接:
sword OCILogon (
OCIEnv *envhp,
OCIError *errhp,
OCISvcCtx **svchp,
CONST text *username,
ub4 uname_len,
CONST text *password,
ub4 passwd_len,
CONST text *dbname,
ub4 dbname_len
);
sword OCILogoff (
OCISvcCtx *svchp
OCIError *errhp
);
5.开始/结束一个会话
先认证用户再建立一个会话连接
sword OCISessionBegin (
OCISvcCtx *svchp, //服务环境句柄
OCIError *errhp,
OCISession *usrhp, //用户会话句柄
ub4 credt, //认证类型
ub4 mode //操作模式
);
*认证类型:
OCI_CRED_RDBMS:用数据库用户名和密码进行认证,则先要设置OCI_ATTR_USERNAME和OCI_ATTR_PASSWORD属性
OCI_CRED_EXT:外部认证,不需要设置用户和密码
OCI_DEFAULT:用户会话环境只能被指定的服务器环境句柄所设置
OCI_SYSDBA:用户要具有sysdba权限
OCI_SYSOPER:用户要具有sysoper权限
Eg:
swResult = OCISessionBegin(svchp, errh,usrhp, OCI_CRED_RDBMS, OCI_DEFAULT);
if(swResult != OCI_SUCCESS && swResult != OCI_SUCCESS_WITH_INFO)
return FALSE;
sword OCISessionEnd (
OCISvcCtx *svchp,
OCIError *errhp,
OCISession *usrhp,
ub4 mode );