I have wamp installed in my system and sql server 2014, and configure so i can access sql server db through php.. with this code:

$serverName = "MY-PC\sqlexpress"; 

$connectionInfo = array("Database"=>"master");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
 echo "Connection established.<br />";
 echo "Connection could not be established.<br />";
 die( print_r( sqlsrv_errors(), true));

that actually works. But when i change "master" with some "customdb" its giving me this error.

Error: 18456, Severity: 14, State: 38. Login failed for user 'NT AUTHORITY\SYSTEM'. Reason: Failed to open the explicitly specified database 'customdb'. [CLIENT: ]

1 Answer 1


It seems you haven't added to service account as a database user to customdb:

USE customdb;

You will also need to grant the needed permissions on database objects to allow a minimally privileged user to access data. I suggest you do this via role membership to facilitate manageability:

USE customdb;
GRANT SELECT ON YourTable TO YourRole;

These symptoms may also be due to the account name and SID beging different, perhaps because the database was restored/attached. Try dropping and recreating the login and user.

  • I added NT AUTHORITY\SYSTEM as database user and give it all roles possible, and still the same problem, its so irritating.. master db doesn't have NT AUTHORITY\SYSTEM as user but its working Jul 7, 2016 at 11:57
  • Are you certain you are connecting to the intended SQL Server instance? Check the SQL Server error log as that should contain this error and perhaps more details.
    – Dan Guzman
    Jul 7, 2016 at 12:12
  • here is 2 prictures with my object explorer in SSMS and the error log file from sqlexpress link Jul 7, 2016 at 12:31
  • It may be that the account name and SID are different, perhaps because the database was restored or attached. Try dropping and recreating the login and user.
    – Dan Guzman
    Jul 7, 2016 at 12:47
  • Man thank you, you save my life i have search the net for 3 days now and finaly is working.. i wanna kiss you Jul 7, 2016 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.