Hi,

I am trying to establish a PDO connection to a remote database (running on a different server than my php app is) as follows:

$dbh = new PDO('mssql:host=www.myaddress.com;dbname=test', 'user', 'pass');

I get this error:

Error!: SQLSTATE[01002] Unable to connect: SQL Server is unavailable or does not exist. Specified SQL server not found. (severity 9)

Can anyone tell me if my dsn string is correct inside of the PDO function, or if I am missing any needed info? The documentation is unclear to me and doesn't contain an example of connecting to a remote db:

http://us3.php.net/manual/en/pdo.construct.php

Thanks for any help,
gm

    You likely need to specify a port number to connect to the DB, and this assumes that the DB host has been configured to allow remote connections. Check with the host or DB admin to find out what port number to use, then append it to the host address after a colon:

    $dbh = new PDO('mssql:host=www.myaddress.com:1234;dbname=test', 'user', 'pass');
    
      NogDog wrote:

      You likely need to specify a port number to connect to the DB, and this assumes that the DB host has been configured to allow remote connections. Check with the host or DB admin to find out what port number to use, then append it to the host address after a colon:

      NogDog, thanks for the reply.

      I tried adding the port number that the db admin gave me but it's still not working. I have also verified that the DB is indeed configured for remote connections. The DB admin is able to connect remotely himself, though he is not doing it through a php app.

      Can I verify with you that, assuming the port is correct, and assuming remote connections are allowed, the connection string I am using should in theory work?

      Can you think of anything else that might be generating this error?

      Thanks again,
      gm

        Can I verify with you that, assuming the port is correct, and assuming remote connections are allowed, the connection string I am using should in theory work?

        It looks like a valid dsn, so that part should be correct.

          Possibly try it without the "www." sub-domain?

            And you also might contact the DB admin to ensure that you have the correct host address, not just port (e.g. if the DB is located on a separate DB cluster/server, it most likely has a different address, such as mysql3.myhost.com).

              Write a Reply...