title: The server principal is not able to access the database under the current security context
body: <p>This seems to be a fairly common question but looking at the help &amp; solutions for other related threads hasn't helped me.</p>
  
  <p>I'm using the PHP code block here (<a href="http://pastebin.com/xSJYyC3y" rel="nofollow">http://pastebin.com/xSJYyC3y</a>) 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:</p>
  
  <p><code>[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.</code></p>
  
  <p>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.</p>
  
  <p>I am using Windows 7 x64, SQL Server 2008 SP1 x64, and PHP 5.4.</p>
  
  <p>Thanks for looking at my problem!</p>