skip to Main Content

I’m trying to connect to a remote ms sql db (not a localhost), but everytime it timeouts before it sucseeds…

I’m pretty sure that the problem is the $serverName variable, is there anyway to check via Plesk Parallels what is the value of that?

    <?php
        $serverName = "server's ip address/database name"; //serverNameinstanceName
        $connectionInfo = array( "Database"=>"database name", "UID"=>"DBusername", "PWD"=>"DBpassword");
        $conn = sqlsrv_connect( $serverName, $connectionInfo);

        if( $conn ) {
             echo "Connection established.<br />";
        }else{
             echo "Connection could not be established.<br />";
             die( print_r( sqlsrv_errors(), true));
        }
    ?>

2

Answers


  1. Chosen as BEST ANSWER

    The problem was that my ip address was not permitted to connect to the database, after I contancted my hosting service provider they gave me that permission and it succeeded.


  2. Try to inject precise port number into ServerName like

    <?php
      $serverName=127.0.0.1SQLEXPRESS,1433; //networkAddrInstanceName,<portNum>
    ?>
    

    Try using Ip address instead NetBios name if you do, cause ICMP protocol is usually blocked due security policy.

    Also, the default port 1433 may be blocked. Should contact server administrator to provide actual connection requisits in that case.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search