cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Calling ESQL from .NET program

Former Member
0 Kudos
2,777

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.

Accepted Solutions (1)

Accepted Solutions (1)

jeff_albion
Product and Topic Expert
Product and Topic Expert

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?

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.

Former Member
0 Kudos

Thanks. I've already decided not to pursue this route, and now I'm especially glad that I have. We don't have the time or inclination to rewrite everything in a native DLL. It's taken us 2 years to get to where we are now and we're very happy not to take a giant step back to where we were in 2010 . . . 😉

Answers (0)