SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Not able to access database - but what object is being sought?


Not able to access database - but what object is being sought?

Author
Message
webrunner
webrunner
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4279 Visits: 3887
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

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"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
MyDoggieJessie
MyDoggieJessie
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6866 Visits: 7394
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" ;-)
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2209 Visits: 872
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
webrunner
webrunner
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4279 Visits: 3887
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

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"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
webrunner
webrunner
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4279 Visits: 3887
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

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"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
MyDoggieJessie
MyDoggieJessie
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6866 Visits: 7394
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" ;-)
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2209 Visits: 872
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search