I have written a (private) stored procedure in T-SQL that is not visible for the user. He has no execute permissions.
CREATE PROCEDURE [dbo].[GetEntries]
AS
BEGIN
SELECT * FROM sometable
END
Then I wrote a CLR stored procedure, for which the user has the execute permissions. This stored procedure calls my private procedure.
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "context connection=true";
conn.Open();
SqlCommand command = new SqlCommand("exec dbo.[GetEntries] ", conn);
...
If I call the public CLR stored procedure, an error occured that I have no rights to call the private stored procedure. I think this is because my connection string is "context connection=true" so the stored procedure is in the user context (user connection).
When I write a public (user visible) T-SQL stored procedure, which calls the private stored procedure, I can execute this stored procedure.
CREATE PROCEDURE [dbo].TSQLPublicSP
AS
BEGIN
Exec dbo.[GetEntries]
END
So my question is, how can I set the connection string in the SQL-CLR stored procedure like the connection it is from the T-SQL stored procedure. I don't want to set the databasename in the SQL-CLR connection string. It would be ok for me if I could get the database name form the SqlContext:
SqlConnection("server=LOCALHOST;integrated security=yes;database=" &
SqlContext.???CurrentDatabase???)