all groups > sql server new users > january 2006 >
You're in the

sql server new users

group:

sp_setapprole problem


sp_setapprole problem Garth Keesler
1/28/2006 2:58:47 PM
sql server new users: Environment: VS2005 C#, SQL Server 2005

I have a routine that accepts an XML doc, creates a connection to the
database, calls sp_setapprole as a stored procedure, inserts two rows
after deserializing the XML, and then closes/disposes of the connection
and the command used to insert the records. Simple stuff. Prob is, it
only works every other call. The call to sp_setapprole is not embedded
in the T-SQL but is invoked with an SQLCommand with commandtype of
stored procedure and the appropriate parameters.


On the failure calls it returns the message, "SQL Error - A severe error
occurred on the current command. The results, if any, should be
discarded." and the following Event occurs on the SQL box:

Event Type: Error
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 18059
Date: 1/28/2006
Time: 2:48:08 PM
User: <me>
Computer: <SQL box>
Description:
The connection has been dropped because the principal that opened it
subsequently assumed a new security context, and then tried to reset the
connection under its impersonated security context. This scenario is not
supported. See "Impersonation Overview" in Books Online.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 8b 46 00 00 14 00 00 00 ‹F......
0008: 08 00 00 00 41 00 50 00 ....A.P.
0010: 50 00 53 00 52 00 56 00 P.S.R.V.
0018: 31 00 00 00 00 00 00 00 1.......

If I call it again, it works. It always works on the first try after
stopping and restarting the app.

Any help greatly appreciated!

Thanx,
Re: sp_setapprole problem Garth Keesler
1/28/2006 3:55:22 PM
Fixed it. You must absolutely call sp_unsetapprole with the appropriate
cookie parameter *before* attempting to close/dispose of any connections
that were in effect before the call to sp_setapprole. Do that and it
works fine.

Garth

[quoted text, click to view]
AddThis Social Bookmark Button