Jump to content

Archived

This topic is now archived and is closed to further replies.

rarex

cannot connect to database

Recommended Posts

please help me I'm desperate!!

 

I have installed PHP version 5.2 - fine

I have SQL Server 2008 - fine

 

Operating system is Windows Server 2008

 

I ran PHP Info and it shows SQL Server loaded as an extension - fine

 

correct DLL's installed including the one that needs to be placed in the windows folder.

 

I am connecting from a standard database connection script (see below) and it keeps coming back as Couldn't connect to server

 

it pauses for a few moments as if it were trying to connect and then spits back the message. If I keep trying it will actually lock the user account in SQL Server and I will have to log in to SQL Server unlock it.

 

This seems as if it is trying to connect but the password is wrong but this cant be..... AND if I log in with the same user name and password into SQL Server that I use in my database connection script, it logs in fine.

 

What have I missed? it doesn't make sense why it wont connect!!!

 

The connection script:

 

$dbhost = 'localhost';

$dbusername = 'theusername';

$dbpasswd = 'thepassword';

$database_name = 'mydatabasename';

 

$connection = mssql_pconnect("$dbhost","$dbusername","$dbpasswd" )

or die ("Couldn't connect to server.");

 

$db = mssql_select_db("$database_name", $connection)

or die("Couldn't select database.");

 

Share this post


Link to post
Share on other sites

There could be any number of reasons but try this one first:

 

Go into sql server and query select @@servername (<instance name>) and put this value instead of localhost.

remove the username and password so you log in as windows authentcation that is if sql server and php are running on the same box.

 

 

$connection = mssql_pconnect('<instance name>','','')

 

Share this post


Link to post
Share on other sites

Something I just noticed, don't know if you did a typo in your post or it's in your code but:

 

$connection = mssql_pconnect("$dbhost","$dbusername","$dbpasswd" )

 

should be mssql_connect not mssql_pconnect

Share this post


Link to post
Share on other sites

Something I just noticed, don't know if you did a typo in your post or it's in your code but:

 

$connection = mssql_pconnect("$dbhost","$dbusername","$dbpasswd" )

 

should be mssql_connect not mssql_pconnect

 

Unless, of course, the OP actually intended to use mssql_pconnect for a persistent connection.

Share this post


Link to post
Share on other sites

Including some better error capture would help find out what the actual problem is :

 

or die ("Couldn't connect to server. The following error occured :<br><br>".mssql_error());

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.