4

I'm trying to convert some existing C# code into a CLR stored procedure. The obvious connection string to use is a context connection ("context connection = true").

The problem I'm running into is some things apparently don't work on this connection type. The latest thing is the SqlConnection.GetSchema method fails. The error just says it is not available on a context connection. Is there a list somewhere of things that won't work on a context connection?

2
  • Can you paste the exception and stack trace? Commented Mar 17, 2009 at 20:23
  • I could but I'm not looking for help with that specific error. The message is very clear. It doesn't work with a context connection. What I'm not able to find is a reason why it doesn't work or a list of other things that may not work. Commented Mar 17, 2009 at 20:38

3 Answers 3

4

You might have already come across this in the MSDN SQL Server 2008 Books Online, however, the following link explains the restrictions imposed when using Context Connections:

Restrictions on Regular and Context Connections

If you post the full exception and stack trace then it may be possible to ascertain from the .NET FX assemblies (using .NET Reflector), or those deployed with SQL 2005/2008, why this exception is thrown.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that link was helpful. I don't have the stack trace handy. I just call DataTable tbl = dbcon.GetSchema("Tables"); and it fails saying it isn't allowed on a context connection.
I'm not really looking for help on the specific error just more info on what else might not work.
2

Someone might find this useful:

    System.Data.DataTable schema = null;
    using (System.Data.SqlClient.SqlCommand cmd = database.Connection.CreateCommand())
    {
        cmd.CommandText = string.Format( "SELECT TOP 1 * FROM {0}", mainTable );
        cmd.CommandType = System.Data.CommandType.Text;
        using (System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader())
        {
            schema = rdr.GetSchemaTable();
        }
    }

Comments

1

After some more seaching I found this list of things that won't work with a context connection here. Some of these are also documented in the SQL Books link above but it doesn't mention them all.

Things that don't work with a context connection.

  • ChangePassword method
  • GetSchema method
  • Connection pooling and associated parameters and methods
  • Transparent failover when database mirroring is used
  • Client statistics PacketSize, WorkstationID, and other client information

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.