Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to use the same dll in my Asp.Net project and in SQL CLR. When my assembly is launched by Asp.Net project my dll uses config-file to get settings. Being launched inside SQL Clr my assembly should get settings from special config-table. I don't know how to find out, from where to get settings without catching exceptions. Is there any better way to know that dll was launched within SQL CLR?

C#
try
{
     //Check for Clr-specific connection
     using (SqlConnection connection = new SqlConnection("context connection=true"))
     {
         return "get settings from sql table";        
     }
}
catch (Exception ex)
{
    return "get settings from config-file";
}
Posted
Updated 11-Mar-15 3:45am
v2

1 solution

Use the SqlContext.IsAvailable property[^]:
C#
if (Microsoft.SqlServer.Server.SqlContext.IsAvailable)
{
    // Load the settings from the SQL table
}
else
{
    // Load the settings from the config file
}
 
Share this answer
 
Comments
Lavisa Lavisa 11-Mar-15 10:52am    
Thank you for your help. It's working.) I really have to look through the Microsoft.SqlServer.Server namespace more carefully.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900