I am developing a C# project that must interact with some legacy C++ code. I do not have control over any part of the C++ code, other than creating the link to my C# code.
Both the C++ code and the C# code must access a Sysbase databse using an ODBC connection. The C++ code opens a connection to a Sybase database using ADO. The connection is then stored in a _ConnectionPtr smart pointer. The C++ code eventually must call my C# code, which is compiled in a separate dll. My C# code also needs to access this same database.
I know how to create a connection string and open an ODBC connection in C#, but I have been instructed to avoid opening a separate connection to the database if at all possible. So what I need to do is have my C# code use the same connection that was opened by the C++ code. How can I pass the connection from the C++ code to the C# code or have the C# code reach back into the C++ code and access the connection? I've been researching options using COM and Marshalling, but I haven't really gotten anywhere. Is it possible for the C++ and C# code to use the same connection? If so how can the connection be communicated from one dll to the other.
Thanks for the help and let me know if any further details would be useful.