Solved

Consume Oracle connection created in C# using C class

Posted on 2007-11-15
15
757 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:Sammy
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
How is the connection represented?
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
the connection should be sent an Oracle Object
string connString = "Data Source=(DESCRIPTION="              
             + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=SERVER)(PORT=1521)))"
             + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
             + "User Id=ID;Password=Password;";

OracleConnection conn = new OracleConnection(connString)
conn.Open();

whats being sent will be the conn object which is an Oracle dataAccess client
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
Well, if you want to pass the connection string to the C part, that is not a big deal, but the connection itself might be problematic. To pass the string, you'd use

using System.Runtime.InteropServices; // DllImport
public class CCode {
  [DllImport("ccode.Dll")]
  public static extern void SetConnectionString(String s);
}

with the function being

void SetConnectionString(LPCSTR s);
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Thus my question how the connection is represented - is that some handle embedded in a class or ...?
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
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?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Author Comment

by:Sammy
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Well, how is it stored in C#? Once that is clear, a matching type for marsholling should be easy to find.
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What is the declaration of the "Oracle DataAccess Object"?
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
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(connString)
conn.Open();
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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?
0
 
LVL 27

Author Comment

by:Sammy
Comment Utility
call to open the connection where :connectstr is a connection string
exec sql connect :connectstr;
thensql execution like so
exec sql select * from............
0
 
LVL 27

Author Closing Comment

by:Sammy
Comment Utility
jkr, you get an A for your effort. had to take a completely different path for this issue
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 82
XML to SQL Table using c# 5 44
Get String split 5 31
FMX TCameraComponent Problem 2 10
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now