0

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:

<?php 
$serverName = "MY-PC\sqlexpress"; 

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

if( $conn ) {
 echo "Connection established.<br />";
}else{
 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

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

USE customdb;
CREATE USER [NT AUTHORITY\SYSTEM];

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;
CREATE ROLE YourRole;
ALTER ROLE YourRole ADD MEMBER [NT AUTHORITY\SYSTEM];
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 – George Panagiotinos Jul 7 '16 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 '16 at 12:12
  • here is 2 prictures with my object explorer in SSMS and the error log file from sqlexpress link – George Panagiotinos Jul 7 '16 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 '16 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 – George Panagiotinos Jul 7 '16 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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