I am going to be writing some code in a C DLL that will be called from an ADO.net program. I need the C code to use the same connection and transaction that the ADO.net program uses. That is, the work that the C code does must happen in the same transaction that the ADO.net code does its work in.
I'm a complete novice at ESQL. I have no idea how to do this, or even if it's possible. Can it be done?
Where does one find information on how to write ESQL code? The documentation is a bit light on detail. It seems to rely on sample code, which isn't answering my questions.
asked 19 Apr '13, 22:58
No. .NET (managed) to native (unmanaged) code is always done through P/Invoke. You could call a native .DLL from within an SATransaction .NET context, but the ESQL DLL would still need to create its own connection back to the database, so it wouldn't be "within the same connection context" as the .NET connection (e.g. you can't "tap in" to the underlying unmanaged connection object that is already held by SAConnection from your ESQL code).
Conversely, if you use the ESQL external environment called directly from the database server, you are supplied the database context to avoid creating this extra connection when invoked, so if you simply wrote everything in an ESQL DLL with this external environment architecture in mind outside of .NET, you could work within an existing connection context as you currently desire - however, as the documentation notes, there is a small performance penalty to call out to external environments, so it's not clear that this process would actually be faster even if you were to implement it.