SQL-Context using Adapter

Posts   
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 19-Dec-2011 22:03:20   

From old server

jwijnker wrote:

Using LLBLGen 3.1 and .Net4 I want to add additional user-info to the SQL-Context (MS-SQL 2008 ).

In the adapter there is no way to get the connection itself to add the information. How can i add context-info to the connection?


http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7711 isn't helping me because it's using selfService.

Frans Bouma | Lead developer LLBLGen Pro
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Dec-2011 03:37:34   

In Adapter, write a DataAccessAdapter partial class in your DBSpecific project and write something like this:

using System.Data.Common;

namespace YourRootNamespace.DatabaseSpecific
{   
    public partial class DataAccessAdapter
    {
        protected override DbTransaction CreateNewPhysicalTransaction()
        {
            var trans = base.CreateNewPhysicalTransaction();

            var factory = GetDbProviderFactoryInstance();
            var command = factory.CreateCommand();
            command.Connection = this.GetActiveConnection();
            command.CommandText = "SET CONTEXT_INFO 0x1256698456";
            command.Transaction = trans;
            command.ExecuteNonQuery();

            return trans;
        }
    }
}
David Elizondo | LLBLGen Support Team