1

i can connect from client PC to SQL Server Express using the following creds. in mgnt sudio:

server: 192.168.44.96\sqldb
auth: windows auth
user name: domain\user
pw: 1234!

Have a LAMP server trying to connect to the above SQL server, here's what the PHP looks like:

$server = '192.168.44.96\sqldb';
$username = 'domain\user';
$password = '1234!';
$database = 'testing123';
$connection = mssql_connect($server, $username, $password);
if($connection != FALSE){
    echo "Connected to the database server OK<br />";
}
else {
    die("Couldn't connect" . mssql_get_last_message());
}

if(mssql_select_db($database, $connection)){
    echo "Selected $database ok<br />";
}
    else {
    die('Failed to select DB');
}

the page displays 'couldn't connect' and the error.log says "unable to connect ot server: 192.168.44.96".

I have also set mssql.secure_connection = On in php.ini and restarted apache2.

any thoughts?

thanks!

hakre
  • 193,403
  • 52
  • 435
  • 836
dan
  • 505
  • 1
  • 8
  • 26
  • We did this at my workplace, and we ended up hosting PHP on a windows box because theres no good drivers for MSSQL on Linux. We got it working but it took 30 secs to connect etc.. – Andreas Stokholm May 21 '12 at 21:52

2 Answers2

1

I can't comment on the PHP part, I only know SQL Server.
But I can tell you: That's not how Windows authentication works.
You can't use Windows authentication and then pass user name and password explicitly to the server. You need to do one of these:

  1. Use SQL Server authentication and pass user name and password explicitly
  2. Use Windows authentication and do not pass user name and password - you will connect automatically with the active Windows user.

Since you're using a Linux server, I'm pretty sure that you can't use Windows authentication. So you have to use SQL authentication (which needs to be enabled on a fresh SQL Server installation), and you have to create an user on the SQL Server.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
  • is there any way to modify the current sql server instance to use mixed mode auth? – dan May 21 '12 at 22:19
  • Yes, see this SO question: http://stackoverflow.com/questions/1393654/how-to-change-from-sql-server-windows-mode-to-mixed-modesql-server-2008 – Christian Specht May 21 '12 at 22:20
  • awesome! changed to mixed mode, added an sql user, connected using sql auth and the new user creds. works great! Thanks! – dan May 21 '12 at 22:41
0

If you have a default sqlexpress installation you probably need to configure your sql server to allow remote access connections. Also I don't know if you can connect with windows auth. At your sql server you can also setup sql authentication and use uid=;pwd=.

YvesR
  • 5,922
  • 6
  • 43
  • 70