0
votes

I am building a website using PHP on Somee Server(somee.com) and Microsoft SQL. Now I have a problem making connection between php and SQL.

Here is my connection code:

<?php
$serverName = "mssql.somee.com"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"myDB","UID"=>"myusername","PWD"=>"mypassword");
$conn = sqlsrv_connect( "mssql.somee.com", $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));} ?>

And it returns me this error:

Connection could not be established. Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. ) )

Anyone knows about it? Thanks very much. Really appreciate it.

1
Isn't Login failed for user 'jason_SQLLogin' a pretty good hint? A password issue maybe? - fvu
Yup, looks like “ jason_SQLLogin” doesn’t have the right credentials, access levels or something else. But this is a very simple credential issue. - Giacomo1968
thanks guys, but seems like the account and password are correct. cos I used it to connect to mssql from ASP - Ben

1 Answers

1
votes

If you say you have the correct username / pass, perhaps the server (some.com) is actively blocking connections to it.

Try using below steps -

  1. On SQL Server (of SOMEE) in Security, make sure that Server Authentication is set to SQL Server and Windows Authentication Mode. This allows SQL server to authenticate username and passwords.

  2. Configure Server firewall to allow connections to SQL server.