Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mssql_connect used to work but not anymore?

Status
Not open for further replies.

irbk

MIS
Oct 20, 2004
578
US
So I have a pretty simple connection script to connect to the SQL database on web.com
Code:
define ('DB_SERVER', 'xxx.xxx.xxx.xxx');
define ('DB_USER', 'username');
define ('DB_PASSWORD', 'password');
define ('DB_NAME', 'thedatabase');
$dbc = mssql_connect (DB_SERVER, DB_USER, DB_PASSWORD)
  or die ('Could not connect to MSSQL');
@mssql_select_db (DB_NAME)
  or die ('Could not select the database');
[\code]
Well, this little script worked just fine for about 2 years.  Last month, web.com "upgraded" our account (and I use the term "upgraded" very loosely as this is the 2nd serious issue we've had since the upgrade) and since our account was "upgraded" the script doesn't work.  Instead I get a nice error message like so
[code]
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xxx.xxx.xxx.xxx in \\HOSTING\DFS....
[\code]
I've attempted contacting web.com, and frankly the cup of coffee that I drank while I was on hold waiting for support to answer was more usefull then support.  They claim that since one can make an ODBC connection to the database through windows (which I can), that it's working just fine and the issue is with my script (even though my script hasn't changed in 2 years and it worked fine before the upgrade).  I've spent about 3 hours this morning trying several different ways to connect via my PHP script and tried several different google searches but I still can't find a solution.  Has anyone run across this before and have an suggestions on how to get my script to work once again?  Remember, this is a hosted site, so I don't have access to the ntwdblib.dll to check what version it is or to edit anything in the php.ini file (however I've checked the phpinfo() and mssql.secure_connection is set to off).

Thanks in advance.
 
Have you looked at the paramerts the ODBC connection uses ? (choose the configure button)
Has the ODBC connect worked with no change on the old server and the new ?
Do you supply any manual info with the ODBC connect e.g password.
Do the standard tools such as mysql query browser work ?
It seems odd that ODBC works and native doesn't.
You error message only shows a warning, I thohght it would have been an error. Do you have any response oodes from the call. (i.e. a call to mysql_errono())
Have you tried a new script which simply connects and returns some rows ?
 
Thanks for your reply.
Yes, I'm using the same login info for the ODBC connection as I am in the script. So I know the server ip is right, the username is right, and the password is right.
MySQL Query Browser does not connect, but as this is an MSSQL database I'm trying to connect to, I'm not sure it would work regardless.
I don't have any error messages other then the "unable to connect". PHP doesn't have very good MSSQL error reporting like it does for MySQL. Even with the limited info I can get, I get nothing more then the "unable to connect"
Yes, I've tried a different script that just connects and either returns a sucessfull connection or dies and I get the same "unable to conenct" message.
 
Hi there irbk,

I assume you have tried a simplification of your script like so?

Code:
$dbc = mssql_connect ('xxx.xxx.xxx.xxx', 'username', 'password')
  or die ('Could not connect to MSSQL');
mssql_select_db ('db_name')
  or die ('Could not select the database');

Remember- It's nice to be important,
but it's important to be nice :)
 
sorry I read it as mysql - i hang my head in shame.
Do you know what provider your using to connect to mssql. If your using the native provider I think you bypass the driver software and it uses internal TDS commands.
Can you put a call to mssql_get_last_message() Perhaps the php lib win't connect. Did the ISP upgrade the db server ?
 
Yes, I did try a simplified version of the script.

Don't really know what you mean by "what provider" I'm using. I just make the MSSQL_Connect statement, so wouldn't that be the provider?
I tried to do the mssql_get_last_message and still only get the "unable to connect".
 
ODBC amd OLEDB may be using the SQL native provider which does not use the TDS software.
PHP will use the TDS native layer so you may be using a differcnt method to connect in both cases.
When you list the avaiable ODBC connections in the ODBC applet, does your datasource say SQL Server or SQL Native Client?
Might be better off posting this in the mssql forum.
Anyhow did you put the call to mssql_get_last_message() ?
 
I'm basically running into the same problem here - except I have control over the server (am attempting to upgrade myself from 5.1.6 to 5.2.6).

PHP is using php_mssql.dll in the extensions directory. I just installed the Native Client drivers - and attempted the upgrade of PHP again - same results - can't connect, then downgrade PHP and it works again.

I'd really like to upgrade so that I can start using the SQL Server 2005 Driver for PHP (just doesn't work on 5.1.6), but I can't break any compatibility with existing sites.
 
Ha - of course just AFTER I post I figured out the problem.

It was the ntwdblib.dll file WITHIN the PHP directory, the old directory had the updated file, not the new PHP directory.

Once I copied that over it worked lickity split.
 
thanks for posting this Borvik. I'm sure it will help out many people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top