先说明一下,我tmboot -y正常启动了服务,但客户端访问时会报错,看ULOG会报错ORA-01012 未登录,而程序里的tpopen返回值是1;如果我修改ubb里的密码故意修改错误,则服务都不能正常启动(也就是说能启动服务说明登录是没有问题的,但前面又报未登录的错)。如果我加上EXEC SQL CONNECT :uid;这样的方式,就可以登录,并且客户端程序就正常使用服务了,但XA方式是不需要再写CONNECT的,所以这里非常困惑。请问如何解决这个问题,我是想用XA正常在tpsvrinit里连接数据库。
[hwt@localhost db]$ cat svrInsert.pc
#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE section;
char *uid="scott/scott@testdb";
EXEC SQL END DECLARE section;
tpsvrinit(int argc, char *argv[])
{
int aa;
argc = argc;
argv = argv;
/* userlog writes to the central TUXEDO message log */
userlog("Welcome to the simple server");
if ((aa=tpopen()) == -1) //按理说这里tpopen会连接数据库,读取ubb配置中的用户密码,
//如果ubb密码错了,就启动不了服务,但现在服务能启动,用客户端访问INSERT服务时,ULOG里会报错说没有登录,可我把下面的CONNECT注释打开的话,就能正常处理客户端请求了,所以应该是登录的问题,但用XA的话就不应该再CONNECT,因为connect 数据库应该是在tpopen时完成的。 {
userlog("connect to Oracle error\n");
return -1;
}else
{
userlog("aa=%d\n",aa);
}
//EXEC SQL CONNECT :uid;
return(0);
}
INSERT(TPSVCINFO *rqst)
{
EXEC SQL insert into dept values (60,'XXX','YYY');
if (sqlca.sqlcode != 0) /*检查是否出错 */
{
printf("insert error, %d:%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
userlog("insert error,%d:%s\n",sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK RELEASE;
tpreturn(TPFAIL, 0, NULL, 0, 0);
}
EXEC SQL COMMIT WORK RELEASE;
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
void tpsvrdone()
{
if (tpclose() == -1)
{
printf("disconnect to Oracle error\n");
return;
}
}
这里是ubb的配置(scott用户的密码已经改成了scott):
*RESOURCES
IPCKEY 123454
DOMAINID simpapp
MASTER simple
MAXACCESSERS 10
MAXSERVERS 20
MAXSERVICES 30
MODEL SHM
LDBAL N
SCANUNIT 10
DBBLWAIT 2
BLOCKTIME 5
*MACHINES
DEFAULT:
APPDIR="/home/hwt/db"
TUXCONFIG="/home/hwt/db/tuxconfig"
TLOGNAME=TLOG
TUXDIR="/tuxedo10/tuxedo10gR3"
TLOGDEVICE="/home/hwt/db/TLOG"
TLOGSIZE=150
localhost LMID=simple
*GROUPS
GROUP1
LMID=simple GRPNO=1 OPENINFO=NONE
ORACLE
LMID=simple GRPNO=5
OPENINFO="Oracle_XA:Oracle_XA+Acc=P/scott/scott+SesTm=120+SqlNet=testdb+LogDIR=."
CLOSEINFO=""
TMSNAME=TMS_ORA10 TMSCOUNT=2
*SERVERS
DEFAULT:
CLOPT="-A"
svrInsert SRVID=10 SRVGRP=GROUP1
*SERVICES
INSERT
[hwt@localhost db]$ ./simpcl sdfdsf
Can't send request to service INSERT
Tperrno = 11
ULOG:
205134.localhost!TMS_ORA10.17384.3086993952.0: LIBTUX_CAT:262: INFO: Standard main starting
205134.localhost!svrInsert.17387.3086993952.0: 04-17-2011: Tuxedo Version 10.3.0.0, 32-bit
205134.localhost!svrInsert.17387.3086993952.0: LIBTUX_CAT:262: INFO: Standard main starting
205134.localhost!svrInsert.17387.3086993952.0: Welcome to the simple server
205134.localhost!svrInsert.17387.3086993952.0: aa=1
211709.localhost!svrInsert.17387.3086993952.0: insert error,-1012:ORA-01012: 没有登录
客户端程序:
#include <stdio.h>
#include "atmi.h" /* TUXEDO Header File */
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
char *sendbuf, *rcvbuf;
long sendlen, rcvlen;
int ret;
if(argc != 2) {
(void) fprintf(stderr, "Usage: simpcl string\n");
exit(1);
}
/* Attach to System/T as a Client Process */
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed\n");
exit(1);
}
sendlen = strlen(argv[1]);
/* Allocate STRING buffers for the request and the reply */
if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating send buffer\n");
tpterm();
exit(1);
}
if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating receive buffer\n");
tpfree(sendbuf);
tpterm();
exit(1);
}
(void) strcpy(sendbuf, argv[1]);
/* Request the service INSERT, waiting for a reply */
ret = tpcall("INSERT", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
if(ret == -1) {
(void) fprintf(stderr, "Can't send request to service INSERT\n");
(void) fprintf(stderr, "Tperrno = %d\n", tperrno);
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
exit(1);
}
(void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);
/* Free Buffers & Detach from System/T */
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
return(0);
}
[hwt@localhost db]$ tmadmin
tmadmin - Copyright (c) 2007-2008 Oracle.
Portions * Copyright 1986-1997 RSA Data Security, Inc.
All Rights Reserved.
Distributed under license by Oracle.
Tuxedo is a registered trademark.
> psc
Service Name Routine Name Prog Name Grp Name ID Machine # Done Status
------------ ------------ --------- -------- -- ------- ------ ------
TMS TMS TMS_ORA10 ORACLE 30001 simple 0 AVAIL
TMS TMS TMS_ORA10 ORACLE 30002 simple 0 AVAIL
INSERT INSERT svrInsert GROUP1 10 simple 1 AVAIL
> psr
Prog Name Queue Name Grp Name ID RqDone Load Done Current Service
--------- ---------- -------- -- ------ --------- ---------------
BBL 123454 simple 0 1 50 ( IDLE )
TMS_ORA10 ORACLE_TMS ORACLE 30001 0 0 ( IDLE )
TMS_ORA10 ORACLE_TMS ORACLE 30002 0 0 ( IDLE )
svrInsert 00001.00010 GROUP1 10 1 50 ( IDLE )
--转自搜狗