Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Not able to access database - but what object is being sought? Expand / Collapse
Author
Message
Posted Friday, February 28, 2014 3:49 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:43 AM
Points: 2,373, Visits: 2,723
Hello experts,

I'm getting reports of a curious error. It is the following:

The server principal ""[principal]"" is not able to access the database ""[database]"" under the current security context.

What makes it curious for me is that I am having trouble tracking down what object the principal (db user) is trying to access. I can't find any reference to the database in question in the code from which the error is being thrown. I've tried searching not only the immediate stored procedure code but also references to the database throughout the db server's SQL codebase (triggers, views, etc.), to no avail. I can't find where this user needs to access the database that would result in the error indicated.

Does anyone know how to trace this kind of dependency? I don't want to just start granting permission to the database without knowing why the permission is needed.

Thanks for any help.

- webrunner


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
Post #1546602
Posted Friday, February 28, 2014 3:54 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 11:40 PM
Points: 3,931, Visits: 7,159
Has the user been mapped to the database? If not, that's most likely the cause of your error. If you're concerned about granting permissions. If the user needs to select or run procedure, they will need to be granted SELECT and EXECUTE at a minimum


______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience"
Post #1546604
Posted Friday, February 28, 2014 4:05 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, September 15, 2014 4:57 AM
Points: 802, Visits: 717
So how does that piece of code look like? What line does the error message point to?

By chance, does the procedure have an EXECUTE AS clause?


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1546606
Posted Friday, February 28, 2014 4:07 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:43 AM
Points: 2,373, Visits: 2,723
MyDoggieJessie (2/28/2014)
Has the user been mapped to the database? If not, that's most likely the cause of your error. If you're concerned about granting permissions. If the user needs to select or run procedure, they will need to be granted SELECT and EXECUTE at a minimum


Thanks - but that's just it. I can't find the relevant code that shows why the login needs this particular database (call it DB1). The error shows up in a web script. When I look at that line, it refers to a stored procedure call in a different database (call it DB2). There are also some views referenced in the stored procedure, but none of those views has a reference to DB1. I've also tried checking triggers on any of the tables called in the procs or views. No reference to DB1 there, either.

Do you know where I might be failing to look to confirm the dependency on this database?

Thanks again!
- webrunner


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
Post #1546607
Posted Friday, February 28, 2014 4:09 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:43 AM
Points: 2,373, Visits: 2,723
Erland Sommarskog (2/28/2014)
So how does that piece of code look like? What line does the error message point to?

By chance, does the procedure have an EXECUTE AS clause?


Hello Erland, thanks for your reply. Please see my other reply for a schematic description of the error and code. There is no EXECUTE AS statement in the procedure. But the error line number does fall right next to a procedure call in the web script. I tried checking that procedure, but it's in a different database and doesn't directly reference the database in the error. But maybe some dependent object somewhere along the line does reference the db. I just can't find it yet.

Thanks again!

- webrunner


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
Post #1546609
Posted Friday, February 28, 2014 4:30 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 11:40 PM
Points: 3,931, Visits: 7,159
Sounds like the front end web application is using a specific user account that does not have access (or no longer has access) to the database it's trying to reach. In some cases with web apps, they may be using an account, that yet uses another account to actually make a connection to the database from their business layer (sort of like a proxy account).

It could also be a scenario where the procedure is calling another procedure, or function, or view, etc in another database that the web account can't reach...

Your web developers need to do some digging to let you know exactly which account is being used, and which procedure is being called. It shouldn't be very difficult for them to pinpoint.


______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience"
Post #1546610
Posted Saturday, March 1, 2014 3:00 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, September 15, 2014 4:57 AM
Points: 802, Visits: 717
You say that the error is on a certain line in a web script where there is a call to a stored procedure which is in "another database".

But is the error with that call itself? Or does the procedure start executing and then runs into this error? An error message from SQL Server includes both procedure name and line number. If the line number is 0, the error is with invocation of that procedure. But of course, if you are looking at this from the web application, the web application may careless drop the information on the floor.

One way to investigate this is to do:

EXECUTE AS LOGIN = 'WebScriptUser'
go
EXEC storedproc @par1, @par2, ...
go
REVERT

This should give you a clearer error message you can work from.





Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1546629
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse