Execute Statement on Connect

Posts   
 
    
Posts: 37
Joined: 21-Oct-2004
# Posted on: 13-Dec-2006 03:53:51   

Not sure if this should go in this forum or another, but here goes:

We need to execute an ALTER SESSION statement when a database connection is first made using the mapper. Is there any way to do this with LLBLGen?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 13-Dec-2006 07:16:00   

You should use the ExecuteActionQuery() method, here are a couple of useful threads: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6245 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7165

Posts: 37
Joined: 21-Oct-2004
# Posted on: 13-Dec-2006 19:03:14   

Okay, got that. How do I execute that every time a new connection is created?

Thanks for the help!

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Dec-2006 02:24:27   

Are you using Adapter or SelfServicing?

With adapter you may take a look at this method in DataAccessAdapter.cs

protected override IDbConnection CreateNewPhysicalConnection(string connectionString)

or with self servicing in DbUtils.cs

public static SqlConnection CreateConnection()

If you make the change there and it works the way you want then you can change the appropriate template to generate this change for you.

Posts: 37
Joined: 21-Oct-2004
# Posted on: 14-Dec-2006 02:27:46   

We're using SelfServing. Isn't CreateConnection supposed to return a new closed connection though?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Dec-2006 05:26:30   

Isn't CreateConnection supposed to return a new closed connection though?

I think what Brian ment was to open the connection inside the CreateConnection method, do your job, then close the connection and return this connection, to be used and re-opened later on by the caller.

Posts: 37
Joined: 21-Oct-2004
# Posted on: 14-Dec-2006 05:40:47   

Yeah, that's what I thought. The problem is that that will throw away the session, which we need to keep around. We're issuing an ALTER SESSION command that will change how queries are handled for the rest of the queries through that connection.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Dec-2006 05:44:52   

Are you sure this will happen?

As the impression I have is that: the closing and openning of the connection is done on the ADO.Net level, and that the connection is valid unless it is being disposed.

Would you please try it out?

Posts: 37
Joined: 21-Oct-2004
# Posted on: 14-Dec-2006 05:55:56   

You bet! I wasn't aware that it worked that way, but I'll give it a shot!