Jump to content
#StayAtHome ×

Archived

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

stockton

Hints on why mssql_connect fails on one PC

Recommended Posts

The following code consistently works on all PCs tried on except my laptop.

Please give me some hints on why this may happen.

    global $dbservertype, $servername, $dbusername, $dbpassword, $dbname, $link;
    $link = mssql_connect($servername, $dbusername, $dbpassword) or die("Unable to connect to T4T database");

 

Share this post


Link to post
Share on other sites

Perhaps you don't have the MSSQL client libraries on your laptop?

 

 

Perhaps the MSSQL extension isn't enabled in PHP?

 

 

It could be a lot of things.  What error message do you get?

Share this post


Link to post
Share on other sites

I do have the client libraries on my laptop.

I do have mssql extensions enabled in PHP.ini

and MSSQL gives no error message that I am aware of.

All I get is the "Unable to connect to T4T database" from my own code(see below) & I am aware of the die on the connect line and I have coded that many different ways but mssql refuses to share any error messages with me.

    $link = mssql_connect($servername, $dbusername, $dbpassword) or die("Unable to connect to T4T database");

    if (!(mssql_select_db($dbname, $link))) {

        echo "Error in DBConnect() = " . mssql_get_last_message();

        sprintf($Message, "At %d in %s Could not select %s at %s as %s",__LINE__, __FILE__, $dbname, $servername, $dbusername);

        trigger_error(E_USER_ERROR, $Message);

        exit;

        }

Share this post


Link to post
Share on other sites

Change the or die("") to or die(mssql_get_last_message())

Share this post


Link to post
Share on other sites

Unfortunately all that, that gives me is a blank screen.

Share this post


Link to post
Share on other sites

Really?

 

 

It shouldn't x.x.

 

 

Try:

 

 

or die("Error: " . mssql_get_last_message());

 

 

Maybe it's blank for some weird reason.  (If it's really blank, that will show just "Error: ".)

 

 

Hrmmmm, this might be an insulting question, but are you positive the host/username/password are correct?

 

Like, you aren't trying to use localhost or something on the laptop are you?

Share this post


Link to post
Share on other sites

As you suspected adding your code and now all I get is "Error. "

host/username/password are all correct

but I do not understand your "Like, you aren't trying to use localhost or something on the laptop are you?".

If you mean am I browsing to localhost I am and the relationship between localhost and 127.0.0.1 is setup in my hosts file; did I mention that this system is on Windows.

If you mean am I using localhost in my configuration file to point to the database, yes I am.

and I am attempting to access the system(on my laptop) from my laptop.

Share this post


Link to post
Share on other sites

Ahhhh ok.

 

 

I thought maybe you were trying to access the MSSQL server on your PC from your laptop using localhost as the host.

 

 

Do the MSSQL client tools connect?

Share this post


Link to post
Share on other sites

Hrmmm I wonder if this is another infamous mssql_connect bug (which are usually caused by out dated client libraries).

 

 

If you use odbc_connect when mssql_connect isn't working, does it magically work?  If so, it's probably a client library issue.

Share this post


Link to post
Share on other sites

I'll try your suggestion even though I have the same version of mssql on my desktop as I have on my laptop and the desktop works fine.

Share this post


Link to post
Share on other sites

Try enabling the "display_errors = on" in your php.ini

This should provide additional logging data in the returned page.

Make sure consider the warnings in the php.ini comments, and perhaps don't do this if your php server is internet visible.

 

Share this post


Link to post
Share on other sites

I did not believe that enabling the "display_errors = on" in your php.ini will help show mssql messages and in fact when I tested your suggestion nothing changed. I still only get corbins suggested 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.