Using sp_setapprole & store procedures

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 22-Feb-2010 19:53:53   

Hi,

I've implemented: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12594&HighLight=1, and up untill now it worked perfectly. Today was the first time I used it for stored procedures and then it won't work.

When I manually open the connection with my custom method GetOpenSqlConnection on the DataAdapter before calling the stored procedure it works, but otherwise it won't. Doesn't a call to a SP come through OpenConnection() on the Adapter?

Non working code:


AppRoleDataAccessAdapter adapter = new AppRoleDataAccessAdapter();
dt = RetrievalProcedures.NsIfrjobsManager(userId, adapter);             

working code:


AppRoleDataAccessAdapter adapter = new AppRoleDataAccessAdapter();
// Manually open:
adapter.GetOpenSqlConnection();
dt = RetrievalProcedures.NsIfrjobsManager(userId, adapter);     

Custom method:


    public SqlConnection GetOpenSqlConnection()
    {
        var connection = this.GetActiveConnection() as SqlConnection;
        if (connection.State == ConnectionState.Closed)
        {
            this.OpenConnection();
        }
        return connection;
    }

Is there a nicer way to achieve this?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Feb-2010 06:05:49   

What is your runtime library version? (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

David Elizondo | LLBLGen Support Team