Sammy
asked on
Consume Oracle connection created in C# using C class
I was wondering if this is possible.
I have a C# wrapper class wrapping a C class
The C class perform database manipulating methods "inserts, updated and deletes".
Now the trick here is the C# class opens the connection to the database and we need the C class to consume this connection, we can send the connection as a parameter from the C# class to one of the methods in the C class, the problem is how to make C class to consume this connection without having to open a new one?
any ideas or pointers will be greatly appreciated
thanks
I have a C# wrapper class wrapping a C class
The C class perform database manipulating methods "inserts, updated and deletes".
Now the trick here is the C# class opens the connection to the database and we need the C class to consume this connection, we can send the connection as a parameter from the C# class to one of the methods in the C class, the problem is how to make C class to consume this connection without having to open a new one?
any ideas or pointers will be greatly appreciated
thanks
How is the connection represented?
ASKER
the connection should be sent an Oracle Object
string connString = "Data Source=(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(P ROTOCOL=TC P)(HOST=SE RVER)(PORT =1521)))"
+ "(CONNECT_DATA=(SERVER=DED ICATED)(SE RVICE_NAME =ORCL)));"
+ "User Id=ID;Password=Password;";
OracleConnection conn = new OracleConnection(connStrin g)
conn.Open();
whats being sent will be the conn object which is an Oracle dataAccess client
string connString = "Data Source=(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(P
+ "(CONNECT_DATA=(SERVER=DED
+ "User Id=ID;Password=Password;";
OracleConnection conn = new OracleConnection(connStrin
conn.Open();
whats being sent will be the conn object which is an Oracle dataAccess client
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know how to pass the connectionstring, that wont be a big deal, I need to pass the connection itself so C doesnt need to open an additional connection since the C# class is creating and opening the connection due to preset requirements
Thus my question how the connection is represented - is that some handle embedded in a class or ...?
ASKER
Yes the connection is created in the C# class which wraps the C class.
this method calls a C method providing 6 params used when updating the database tables and the Idea is to send the connection as object as a parameter to the C method
C# class uses the InteropServices and DllImport the C class
the connection object does not need to be an Oracle DataAccess client. we can even use ODBC if Oracle will not handle this type of converion between C# and C
does this make any sense?
this method calls a C method providing 6 params used when updating the database tables and the Idea is to send the connection as object as a parameter to the C method
C# class uses the InteropServices and DllImport the C class
the connection object does not need to be an Oracle DataAccess client. we can even use ODBC if Oracle will not handle this type of converion between C# and C
does this make any sense?
I think I got that. But, how is it stored? You won't be able to send a C# object to a C function, but is the connection object storing some sort of handle and if so, what basic type is that?
ASKER
thats the problem, my knowledge in C is limited and I have no idea how to store the connection object to make it usable in C
Well, how is it stored in C#? Once that is clear, a matching type for marsholling should be easy to find.
ASKER
Connection object is just an Oracle DataAccess Object. what do you mean by how it stored? its a C# method that returns an object.
is that what you mean or am I missing something there?
Thanks
is that what you mean or am I missing something there?
Thanks
What is the declaration of the "Oracle DataAccess Object"?
ASKER
C# uses these using statements to reference the Oracle.DataAcess.dll which is added as a reference in VS.Net 2005
using System.Data;
using Oracle.DataAccess.Client;
connection object is declared like this
OracleConnection conn = new OracleConnection(connStrin g)
conn.Open();
using System.Data;
using Oracle.DataAccess.Client;
connection object is declared like this
OracleConnection conn = new OracleConnection(connStrin
conn.Open();
Well, if you cannot find and more specific documantation on that, you'll probably have to resort to passing the connection string. How is the C code using the connection?
ASKER
call to open the connection where :connectstr is a connection string
exec sql connect :connectstr;
thensql execution like so
exec sql select * from............
exec sql connect :connectstr;
thensql execution like so
exec sql select * from............
ASKER
jkr, you get an A for your effort. had to take a completely different path for this issue