Question

I have a SQL CLR stored procedure written in c# (.NET4). Its purpose is to allow a trigger on a table in a SQL Server 2012 database to call a web service which then processes the data in that table.

However, there are several different databases which will all have triggers using this assembly. My web service needs to know which database is triggered the call to it in order to know where to get the data from.

I could simply add a parameter to my stored procedure but I want to keep things simple from the database side. Is there any way, in .NET, to obtain information about the database to which the assembly is attached?

Was it helpful?

Solution

Aah, found one:

This still opens a context connection to the database, but it's about the only way I can see.

using (SqlConnection conn = new SqlConnection("context connection=true"))
{
    conn.Open();
    string dbName = conn.Database
}

That's from an MSDN article. Also, the MSDN article on Context Connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top