Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Pro*C Database connection - How do I identify a connection

Re: Pro*C Database connection - How do I identify a connection

From: EAdler <eadler-at_at_NO_SPAMndsisrael-dot.com>
Date: 2000/05/22
Message-ID: <8gb8a6$hkv$1@news.netvision.net.il>#1/1

Check "concurrent connections" in your Oracle8 "Advanced Pro*C/C++ Applications" guide

or define multi-context Pro*C code using the Pro*C "threads=yes" precompiler option.

In your code add at initialization:
EXEC SQL ENABLE THREADS For each seperate database login initialize a context EXEC SQL BEGIN DECLARE SECTION
    sql_context ctx ;
EXEC SQL END DECLARE SECTION ; EXEC SQL CONTEXT USE :ctx;
EXEC SQL CONNECT :usrpass ;

To switch context for current instance use: EXEC SQL CONTEXT USE :releventcontext;
Before that instance's database access;

Be sure to commit release rollback these contexts seperately AND use EXEC SQL CONTEXT FREE :ctx to deallocate Oracle resources.

E Adler

Don Chambers wrote in message
<4s61isgb8m4jirg7cpuosvj08up3r0v8u2_at_4ax.com>...
>I have written a class which encapsulates my Pro C code. This class
>has a member function that connects to the database.
>The problem:
> If I have 2 instances of the class instatiated each instance should
>be required to connect. This does not seem to work correctly. If I
>declare one instance of the class and connect to the database and then
>declare a second instance this second instance can issue commands
>without having to connect. It seems to be able to use the first
>classes connection.
>This can cause big problems when using transaction. Suppose the
>following:
>Create instance S1 of the class
>Connect to the databse with S1
>Begin a transaction with S1
>Insert using S1
> Another client creates another isntance of the class called S2
> S2 inserts into the database
> S2 commits
>S1 issues a rollback - this fails because the commit for s2 commited
>this work because it uses the same connection.
>
>This code is for the middle tier of an application using CORBA so it
>may be called by many clients - each with its own instance of my
>class. It is essential that I have a way to identify the database
>connection.
>
>Is it possible to get a handle from the connection and then use this
>handle when I execute SQL queries?
>
>How do you handle this?
>
>Thanks,
> Don
> dchamber_at_mindspring.com
>
>
Received on Mon May 22 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US