Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (localhost)

Posted on 2008-11-05
12
Medium Priority
?
11,477 Views
Last Modified: 2013-12-13
I installed PHP on IIS. After configured I manage to connect to the MSSQL DB but there is a warning message. I have no idea what it means
(Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (localhost) in C:\Inetpub\wwwroot\global.php on line 39).
0
Comment
Question by:risk-x
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 4

Expert Comment

by:obareey
ID: 22884312
are you sure your SQL server is running and give correct username/password to the function?
0
 
LVL 6

Expert Comment

by:dwaynecharrington
ID: 22884628
You've entered your username, password or hostname incorrectly. Check your details and try again. You might also need to connect to a specific port.
0
 
LVL 17

Expert Comment

by:nplib
ID: 22888540
can you post your code?

other wise we are guessing.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:risk-x
ID: 22891715
This is my code. Thx

<?php

//$webhost = '';
//$internalhost = '';
$dbhost ='(localhost)';
$dbuser = 'sa';
$dbpasswd = 'sasa';
$dbname   = 'companylog';




if(!($s = mssql_connect($dbhost, $dbuser, $dbpasswd))) ;

if(!mssql_select_db($dbname)) ;



function mssql_setup() {
      global $dbhost;
      global $dbname;
      global $dbuser;
      global $dbpasswd;
}

?>
0
 
LVL 17

Expert Comment

by:nplib
ID: 22896943
remove the brackets

$dbhost = 'localhost'
0
 

Author Comment

by:risk-x
ID: 22901757
after removed the brackets $dbhost = 'localhost' still the same warning message coming out.
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in C:\Inetpub\wwwroot\global.php on line 30
I think is the setting I missed up. I tried in the ODBC but it show connection successfully connected to local DB. The same script I get from the server to my local computer but there is no such message coming out in the server.
0
 
LVL 17

Expert Comment

by:nplib
ID: 22906052
is the mssql server running on the same server where this php file is being served?
0
 

Author Comment

by:risk-x
ID: 22919500
Yes  the mssql server running on the same server where the PHP file is being served. The PHP file is able coonect to the local DB. I just dont know why this message show out as the PHP file is connected with the local DB. There is no problem connect to the local DB, all the data from the DB able to pull out when served the php file. But there is a message showing out on the PHP file ."Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost"
0
 
LVL 4

Accepted Solution

by:
obareey earned 2000 total points
ID: 22920260
if you don't have problem reading data from the server and don't wanna see tihs message, you can put an @ before the function like this:
@mssql_connect(...
0
 
LVL 17

Expert Comment

by:nplib
ID: 22941817
try using the actual IP address,

the MS SQL server may not accept localhost
0
 

Author Closing Comment

by:risk-x
ID: 31513439
Thx a lot after i put @mssql_connect(... there is no warning message coming out alrdy. thx alot.
0
 

Expert Comment

by:previewservices
ID: 23792917
UPDATE!

I got the newest version of ntwdblib.DLL and i got a new message:

Error: [2] mssql_connect() [function.mssql-connect]: message: Login failed for user ''. The user is not associated with a trusted SQL Server connection. (severity 14)Error: [2] mssql_connect() [function.mssql-connect]: Unable to connect to server: 10.100.25.77
<?php
function customError($errno, $errstr)
{
	echo "<b>Error:</b> [$errno] $errstr";
}
 
set_error_handler("customError");
mssql_connect("xx.xx.xx.xx", "sa", "password");
?>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question