Reputation: 5024
This seems to be a fairly common question but looking at the help & solutions for other related threads hasn't helped me.
I'm using the PHP code block here (http://pastebin.com/xSJYyC3y) to try to connect and query a SQL Server database. The connection seems to work, but when making a query, I get the following error message:
[Microsoft][SQL Server Native Client 11.0][SQL Server]The server principal "my_username" is not able to access the database "database_name" under the current security context.
I only get this error when connecting to the server via PHP, if I do it manually through the MS SQL Management Studio, then everything works fine.
I am using Windows 7 x64, SQL Server 2008 SP1 x64, and PHP 5.4.
Thanks for looking at my problem!
Upvotes: 1
Views: 4831
Reputation:
If you can run the query through SSMS, but get a security issue through PHP, you are most likely experiencing an issue with wrong impersonation.
Generally, you'll have two different security issues in play:
Do note that if your query touches several databases, or especially if it includes something that explicitly touches the filesystem (perhaps on a shared folder), you need to check rights on all servers and all folders that are in play.
Also, if you are executing a stored procedure, make sure that you don't have the issue with EXECUTE AS OWNER
. One example of this can be seen here
If that doesn't help you could still look into the security of the database files on your Windows box and try to - temporarily - relax the security to the folder to see if that changes anything.
Upvotes: 1