Previous Next

Thread: mssql_connect() failed with remote SQL Server

Last post 07-26-2008 8:36 AM by MainMa. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 07-17-2008, 7:50 AM

    • MainMa
    • Not Ranked
    • Joined on 07-17-2008, 7:31 AM
    • Posts 3
    • MainMa

    mssql_connect() failed with remote SQL Server

    Hello.

     

    I have a problem with mssql_connect() when connecting to SQL server over network.

    My computer is inside a domain. There are two SQL servers: the first one on my PC (on localhost), the second one on a Windows Server 2008 remote computer (remote) inside the domain. Both are SQL Servers 2005.

    On localhost, I have IIS7 with PHP5 running through Isapi. When I try to connect to the SQL Server on localhost with $this->Link mssql_connect();, it works great. But $this->Link mssql_connect('remote'); fails with "mssql_connect(): Unable to connect to server" error.

     

    I tried everything described in the comments at http://www.php.net/manual/en/function.mssql-connect.php. Nothing seems to work, and I cannot connect to SQL Server on remote neither through Windows authentication, nor through SQL one. By the way, I can connect to remote (both with Windows authentication and SQL one) with SQL Server Management Studio.

    What's the problem?

     

    PS. On remote, both TCP/IP and Named Pipes are enabled. Disabling firewalls on localhost and remote does not solve the problem.

  • 07-17-2008, 11:21 AM In reply to

    Re: mssql_connect() failed with remote SQL Server

    Logs, error messages?

    Jeff

    Look for Wrox's new book Professional IIS 7 in your local bookstore, or order now at Amazon.com
  • 07-17-2008, 12:07 PM In reply to

    • MainMa
    • Not Ranked
    • Joined on 07-17-2008, 7:31 AM
    • Posts 3
    • MainMa

    Re: mssql_connect() failed with remote SQL Server

    jeff@zina.com:

    Logs, error messages?

    Jeff

    Nothing at all. On PHP side, just a:

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: (Server name) in G:\...\data.php on line 16

    pointing to the line with $this->Link = mssql_connect('...');. Then, if I check $this->Link, it's null.

    On SQL side, I don't see anything helpful in Windows logs.

  • 07-23-2008, 11:37 PM In reply to

    • ciwni
    • Top 500 Contributor
    • Joined on 12-07-2007, 5:57 AM
    • Posts 13
    • ciwni

    Re: mssql_connect() failed with remote SQL Server

    Possibly the connection string is not right.

    http://www.sqlstrings.com/SQL-Server-connection-strings.htm

  • 07-24-2008, 11:56 AM In reply to

    • knox203
    • Not Ranked
    • Joined on 07-24-2008, 3:53 PM
    • Posts 3
    • knox203

    Re: mssql_connect() failed with remote SQL Server

      We are experiencing the same issue with our new server as well. Server2008 + IIS7 + PHP 5.2.6, calling a remote SQL server with mssql_connect() gives us an "Unable to connect to server" error, but when I run the php connect file with php.exe from the command line on the server, it returns no errors. I'll try the connection strings and see if that changes anything... but quite a weird issue I must say!

  • 07-24-2008, 1:14 PM In reply to

    • knox203
    • Not Ranked
    • Joined on 07-24-2008, 3:53 PM
    • Posts 3
    • knox203

    Re: mssql_connect() failed with remote SQL Server

     Couldn't get much figured out with the connection strings... maybe I'm doing it wrong? I should note that I can connect, and query the SQL server in question just fine with odbc_connect(). Anyone have any clues as to what would cause this issue?

  • 07-24-2008, 4:30 PM In reply to

    • knox203
    • Not Ranked
    • Joined on 07-24-2008, 3:53 PM
    • Posts 3
    • knox203

    Re: mssql_connect() failed with remote SQL Server

     I found a solution that worked for me! Visit http://www.userscape.com/helpdesk/index.php?pg=kb.page&id=13 and download the ntwdblib.dll file (alternatively, click HERE), make a backup of the original dll residing in your PHP root directory, then replace the original with this new one. I then restarted IIS and BAM, mssql_connect was working fine, and was pulling data!

     Hope this works for you too!!

  • 07-26-2008, 8:36 AM In reply to

    • MainMa
    • Not Ranked
    • Joined on 07-17-2008, 7:31 AM
    • Posts 3
    • MainMa

    Re: mssql_connect() failed with remote SQL Server

    knox203:
    I found a solution that worked for me! Visit http://www.userscape.com/helpdesk/index.php?pg=kb.page&id=13 and download the ntwdblib.dll file [...] Hope this works for you too!!

    No, it doesn't.

    Well, I reinstalled yesterday SQL Server, installed PHP with FastCGI instead of ISAPI and reconfigured all the stuff. It works.

    Seems that it works with PHP with FastCGI, but not with PHP with ISAPI. But not sure.

Page 1 of 1 (8 items)
Page view counter