UlfL
UlfL

Reputation: 79

How can C# code check if a Context Connection (an in-process-only connection,) can be used?

I have written a C# library assembly. It is in a NUGET and contains functions that can be called both from T-SQL scripts (CLR-integration) and from other .net-code. I like the code to be able to check what context it is run in. That is, if a Context Connection (in-process-only connection) is available or not. (If it is I will an entry to a logtable when an exception occours.)

How can a method in a C#-class best determine if the code is executed “in-process” on a SQL Server? If a SqlConnection("context connection=true") can be used? (I do not like to call SqlConnection("context connection=true") and get an System.NotSupportedException if the code is not run in an SQL Server.)

Upvotes: 1

Views: 717

Answers (1)

Niels Berglund
Niels Berglund

Reputation: 1698

You can check SqlContext.IsAvailable.

Upvotes: 1

Related Questions