#1 Le 18/05/2012, à 08:49
- Nouri2012
OCISessionPoolCreate Porblème de connection
Bonjour,
Mon os: linux(ubuntu)
Pour compiler le programme tapez: g++ -lm -lclntsh -o file.o file.cpp -I /usr/include/oracle/11.2/client -I /usr/local/lib -L /usr/lib/oracle/11.2/client/lib/
J'ai utilisé un programme qui me de se connecter a une db oracle
Le problème est quand j'utilise des char normale pour les paramettre de connection, la connection OK
par contre quand on utilise wchar_t (username, passwd, target_db) la connection OK
Si qlq1 a une idée a propos le problème de wchar_t et char mrci de me repondre
ci dessous le programme utilise char normal===>OK
#include <stdio.h>
#include <string.h>
#include <oci.h>
#include <ocidfn.h>
#include <wchar.h>
#include <stdlib.h>
/* Oracleユーザ情報 */
static const char* username = "USR_CRMP";
static const char* passwd = "USR_CRMP";
static const char* target_db = "test";
static OraText* username = (OraText*)malloc(8);
static OraText* passwd = (OraText*)malloc(8);
static OraText* target_db = (OraText*)malloc(4);
size_t res1= wcstombs((char*)username, usernamel,8);
size_t res2= wcstombs((char*)passwd, passwdl,8);
size_t res3= wcstombs((char*)target_db, target_dbl,4);
/*static const char* connMin = "20";
static const char* connMax = "20";
static const char* connInc = "1";*/
int main(int argc, char* argv[])
{
static OCIEnv* envhp; /* OCI環境ハンドル */
static OCIError* errhp; /* エラーハンドル */
static OCISvcCtx** svchp; /* サービスコンテキストハンドル */
OCISPool *spoolhp; //! セッションプール・ハンドル
OraText *poolName = (OraText*)"orcl"; //! セッショ
sb4 poolNameLen ; //! セッションプー
int connMax = 20; //! コネクション最大数
int connMin = 20; //! コネクション最小数
int connInc = 1; //! コネクションインクリメント幅
sword status = OCI_SUCCESS;
/* 環境ハンドルの初期化 */
status = OCIEnvCreate(&envhp, OCI_DEFAULT, NULL, NULL, NULL,
NULL, 0, NULL);
printf("status OCIEnvCreat%d\n",status);
/* エラーハンドルの割り当て */
status = OCIHandleAlloc(envhp, (dvoid**)&errhp, OCI_HTYPE_ERROR,
0, NULL);
printf("status OCIHandleAlloc%d\n",status);
status = OCIHandleAlloc(envhp, (dvoid **)&spoolhp,
OCI_HTYPE_SPOOL, (size_t) 0, (dvoid **)
0);
printf("status OCIHandleAlloc%d\n",status);
// セッションプール生成
printf("username %ls\n", username);
printf("passwd %ls\n", passwd);
printf("target_db %ls\n", target_db);
status = OCISessionPoolCreate((OCIEnv*)envhp, errhp, spoolhp,
(text **)&poolName, (ub4*)
&poolNameLen,
(OraText *)target_db, (sb4)strlen
((const char *)target_db),
connMin, connMax, connInc,
(text*) username, (ub4) strlen
((char *)username),
(text *) passwd, (ub4) strlen
((char *)passwd),
OCI_SPC_STMTCACHE
);
printf("status OCISessionPoolCreate%d\n",status);
status = OCISessionGet((OCIEnv*) envhp, (OCIError*)errhp, (OCISvcCtx**)&svchp, NULL,
(text *) poolName,
(ub4) poolNameLen,
NULL, 0, NULL, 0, NULL,
OCI_SESSGET_SPOOL);
printf("status OCISessionGet%d\n",status);
return 0;
}
Ci-dessous problème de connection
Connection KO ===> On utilise wchar_t
#include <stdio.h>
#include <string.h>
#include <oci.h>
#include <ocidfn.h>
#include <wchar.h>
#include <stdlib.h>
/* Oracleユーザ情報 */
static OraText* username = (OraText*)malloc(8);
static OraText* passwd = (OraText*)malloc(8);
static OraText* target_db = (OraText*)malloc(4);
static const wchar_t* usernamel = L"USR_CRMP";
static const wchar_t* passwdl = L"USR_CRMP";
static const wchar_t* target_dbl = L"test";
/*static const char* connMin = "20";
static const char* connMax = "20";
static const char* connInc = "1";*/
int main(int argc, char* argv[])
{
static OCIEnv* envhp; /* OCI環境ハンドル */
static OCIError* errhp; /* エラーハンドル */
static OCISvcCtx** svchp; /* サービスコンテキストハンドル */
OCISPool *spoolhp; //! セッションプール・ハンドル
OraText *poolName = (OraText*)"orcl"; //! セッショ
sb4 poolNameLen ; //! セッションプー
int connMax = 20; //! コネクション最大数
int connMin = 20; //! コネクション最小数
int connInc = 1; //! コネクションインクリメント幅
sword status = OCI_SUCCESS;
/* 環境ハンドルの初期化 */
status = OCIEnvCreate(&envhp, OCI_DEFAULT, NULL, NULL, NULL,
NULL, 0, NULL);
printf("status OCIEnvCreat%d\n",status);
/* エラーハンドルの割り当て */
status = OCIHandleAlloc(envhp, (dvoid**)&errhp, OCI_HTYPE_ERROR,
0, NULL);
printf("status OCIHandleAlloc%d\n",status);
status = OCIHandleAlloc(envhp, (dvoid **)&spoolhp,
OCI_HTYPE_SPOOL, (size_t) 0, (dvoid **)
0);
printf("status OCIHandleAlloc%d\n",status);
// セッションプール生成
printf("username %ls\n", username);
printf("passwd %ls\n", passwd);
printf("target_db %ls\n", target_db);
status = OCISessionPoolCreate((OCIEnv*)envhp, errhp, spoolhp,
(text **)&poolName, (ub4*)
&poolNameLen,
(OraText *)target_db, (sb4)wcslen
((const wchar_t *)target_db),
connMin, connMax, connInc,
(text*) username, (ub4) wcslen
((wchar_t *)username),
(text *) passwd, (ub4) wcslen
((wchar_t *)passwd),
OCI_SPC_STMTCACHE
);
printf("status OCISessionPoolCreate%d\n",status);
status = OCISessionGet((OCIEnv*) envhp, (OCIError*)errhp, (OCISvcCtx**)&svchp, NULL,
(text *) poolName,
(ub4) poolNameLen,
NULL, 0, NULL, 0, NULL,
OCI_SESSGET_SPOOL);
printf("status OCISessionGet%d\n",status);
return 0;
}
Hors ligne