gpt4 book ai didi

c++ - 使用 OCI_SUCCESS_WITH_INFO 进行 OCILogon 后获取 OCI_INVALID_HANDLE

转载 作者:太空狗 更新时间:2023-10-29 21:49:05 26 4
gpt4 key购买 nike

我创建了以下配置文件。

create profile EXPTESTPROF limit failed_login_attempts unlimited password_life_time 1/24/60/60 password_reuse_time unlimited password_reuse_max unlimited password_verify_function null password_lock_time 1  password_grace_time 31;

alter user exptest profile EXPTESTPROF;

当我尝试从命令提示符登录时,它成功登录并显示以下错误消息。

ERROR:ORA-28002: the password will expire within 30 days

Till that I am fine.

However I wrote one small program for OCI login and some actions.

When I call OCILogon with the above user it returns 1 that addreses OCI_SUCCESS_WITH_INFO.

After that I i trying to fetch OCI_HTYPE_SVCCTX using OCIAttrGet it returns -2 which addreses OCI_INVALID_HANDLE.

Why handle is getting corrupted? IS there any way to overcome this issue and work till grace period ends?

Please find sample OCI client below.

#include "stdio.h"
#include "oci.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#pragma comment(lib, "%ORACLE_HOME%\\oci\\lib\\MSVC\\oci.lib")

void main()
{
int errcode = 0;
int rc = 0;
sb4 ociErrVal = 0;
char *ErrTxt = NULL;
ub4 BufLen = 1024;
size_t DBNameLen = 0;
size_t PasswdLen = 0;
size_t UserLen = 0;

OCISvcCtx *p_svc = NULL;
OCIEnv *p_env = NULL;
OCIError *p_err = NULL;
OCIStmt *p_sql = NULL;
OCIDefine *p_dfn = (OCIDefine *) 0;
OCIBind *p_bnd = (OCIBind *) 0;

const unsigned char *UserID = (const unsigned char*)"exptest";
const unsigned char *Password = (const unsigned char*)"oracle";
const unsigned char *DBName = (const unsigned char*)"ORCL10G";

if (UserID != NULL)
{
UserLen = strlen ((char *)UserID);
}

if (Password != NULL)
{
PasswdLen = strlen((char *)Password);
}

if (DBName != NULL)
{
DBNameLen = strlen((char *)DBName);
}

if (ErrTxt != NULL) {
BufLen = 0;
ErrTxt[0] = '\0';
ErrTxt[1] = '\0';
ErrTxt[2] = '\0';
ErrTxt[3] = '\0';
}

rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0, /* Initialize OCI */
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 );

/* Initialize evironment */
rc = OCIEnvInit( (OCIEnv **) &p_env, OCI_DEFAULT, (size_t) 0, (dvoid **) 0 );

/* Initialize handles */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_err, OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0);
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_svc, OCI_HTYPE_SVCCTX,
(size_t) 0, (dvoid **) 0);


/* Connect to database server */
rc = OCILogon(p_env,
p_err,
&p_svc,
UserID,
(ub4) UserLen,
Password,
(ub4) PasswdLen,
DBName,
(ub4) DBNameLen);

if (rc != 0) {
OCIErrorGet((dvoid *)p_err,
(ub4) 1,
(text *) NULL,
&errcode,
(unsigned char *) ErrTxt,
BufLen,
OCI_HTYPE_ERROR);
}

rc = (long) OCIAttrGet(p_svc,
(ub4) OCI_HTYPE_SVCCTX,
(dvoid *) &p_svc,
(ub4) NULL,
(ub4) OCI_ATTR_SERVER,
p_err);

rc = OCILogoff(p_svc, p_err); /* Disconnect */
rc = OCIHandleFree((dvoid *) p_sql, OCI_HTYPE_STMT); /* Free handles */
rc = OCIHandleFree((dvoid *) p_svc, OCI_HTYPE_SVCCTX);
rc = OCIHandleFree((dvoid *) p_err, OCI_HTYPE_ERROR);
}

最佳答案

问题出在 OCI Api 中,已在 oracle11g R2 中修复 –

关于c++ - 使用 OCI_SUCCESS_WITH_INFO 进行 OCILogon 后获取 OCI_INVALID_HANDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com