These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Application Roles with Nhibernate
PostPosted: Wed Dec 12, 2007 6:07 pm 
Newbie

Joined: Wed Mar 28, 2007 6:22 pm
Posts: 1
Hibernate version:
v1.1.4322

I'm trying to get SQL Server application roles working with nhibernate. I can do this with ASP.NET and now LINQ, but we have a fairly large library of nhibernate code that I need to get working with application roles.

The problem is I don't know how to get at the underlying connection on NHibernate so that I can call sp_setapprole to elevate privileges before a query is sent to the server. I need to attach to a connection state change event of some sort to pre-inject execution of that stored procedure.

How would I do this with nhibernate? Am I utterly screwed?


Top
 Profile  
 
 Post subject: RE: Setting Application Roles
PostPosted: Fri May 23, 2008 6:14 pm 
Newbie

Joined: Fri May 23, 2008 6:04 pm
Posts: 2
I was able to find a solution to execute code after connection. the link to the forum is at: http://forum.hibernate.org/viewtopic.ph ... highlight=

It was posted by BillHawes:

You can obtain an IDbConnection object from the NHibernate session, and execute any commands using this. The following code assumes that the session object is an open NH session, and runs stored procedure MyStoredProc.

IDbConnection cn = session.Connection;
IDbCommand cmd = cn.CreateCommand();

cmd.CommandType = CommandType.Text;
cmd.CommandText = "SP_SetAppRole @RoleName = 'Users', @Password = 'Password'";
cmd.ExecuteNonQuery();

What you can't currently do is run a stored procedure that returns data and map the data to persistent objects.

You also need to be aware that if your stored procedure amends the data in your tables, this will not be reflected in any persistent objects already loaded.

I hope this is what you're looking for.

Good Luck!


Top
 Profile  
 
 Post subject: Re: Application Roles with Nhibernate
PostPosted: Mon May 26, 2008 3:15 am 
Newbie

Joined: Thu May 22, 2008 1:46 pm
Posts: 6
jjacksonRIAB wrote:
I need to attach to a connection state change event of some sort to pre-inject execution of that stored procedure.


I have the same problem, as you can see in my post Code to be executed after any connection.open(), and I got from eluxa the same answer (s)he gave you.

I hope there is a solution. I'm sure there must be one! If somone gives you the right suggestion, please share it with me!

Pietro


Top
 Profile  
 
 Post subject: Re: Application Roles with Nhibernate
PostPosted: Wed May 28, 2008 9:08 am 
Newbie

Joined: Thu May 22, 2008 1:46 pm
Posts: 6
ptoniolo wrote:
I have the same problem, as you can see in my post Code to be executed after any connection.open()


By implementing a ConnectionProvider you can obtain what you need. I described my solution in my original post's thread: http://forum.hibernate.org/viewtopic.php?p=2386466.

If this solves your problem too, please rate this answer to give me the credits!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.