I am working in an environment in which enterprise host application is calling client applications with implemented COM interface via ProgID. This is the way how programmers of host application allow to enhance application with plugins.
Host app <-> COM interface <-> Client app
The client app can use methods from provided COM interface.
One of that method is RunSqlQuery(rawSqlQuery)
. It has possibilities to fully communicate with SQL within the scope of a logged-in user of the host application (based on connection authentication type it could be Windows or SQL user).
What I am looking for is a way to get a current connection context which was started from the host application and use it as a connection for DbContext.
Why?
For clarity, where is the problem, something similar is well known in the SQL CLR world:
In SQL CLR UDF there is possibility to use context connection=true
as a connection string for instance of SqlConnection (more here).
In the link above they wrote:
The connection is in a different database session than the stored procedure or function, it may have different SET options, it is in a separate transaction, it does not see your temporary tables, and so on.
And in other places in that link:
You probably want the stored procedure or function to execute in the context of that connection, along with its transaction, SET options, and so on. This is called the context connection.
The context connection is an in-process-only connection, so it can contact the server "directly" by bypassing the network protocol and transport layers to send Transact-SQL statements and receive results.
Start LocalDB and connect to LocalDB To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1. mdf .
Open the edmx (go to properties, the connection string should be blank), close the edmx file again. Open the app. config and uncomment the connection string (save file) Open the edmx, go to properties, you should see the connection string uptated!!
If you work in asp.net core you just need to configure the connectionstring in your appsettings.json file. Your connectionstring settings are usually shown in the host. If you cannot find it just ask the online consultant about your connection string. This is how I solved my problem with connection when I had quite similar problems with connection
appsettings.json
"ConnectionStrings": { DefaultConnection": "Here_is_the_connectionstringSettings_that_is_given_by_your_host"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With