Connecting Php with MSSQL server 2008 remotely

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erpraveen
    New Member
    • Oct 2011
    • 3

    Connecting Php with MSSQL server 2008 remotely

    Hi,
    I have to connect php with MSSQL server 2008 over other network.
    Router is used in between and port number 1433 is forwarded to IP of the machine .
    When i attempt to make connection without using router, I am able to make connection and when router is used,connection is made but database is not selected.
    Error "unable to select database".
    below is code of my connection.

    $a=mssql_connec t('1.23.182.244 \SQLSERVER','Un ame','Pass');

    where 1.23.182.244 is the ip of router from where port no. 1433 is forwarded to other machine where sql server is installed.
    SQLSERVER is the name of instance.

    Thanks in advance.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Trying adding the default database on your connection string. When you said without using the router, do you mean your PHP is in the same machine as your db?

    ~~ CK

    Comment

    • erpraveen
      New Member
      • Oct 2011
      • 3

      #3
      No friend,
      Both are on different network.
      but in that case i din't forwarded port to machine i mean i din't used router.
      both were on different network and we din't used router.
      and connection was established and data was retrieved.
      but when router is used connection is established but database is not selected.

      Comment

      • erpraveen
        New Member
        • Oct 2011
        • 3

        #4
        Hi,
        My problem is solved.
        Here I am explaining how to connect php with MSSQL server(which is behind router) over other network.

        PC1:php installed.
        PC2:mssql server installed.

        steps are as follows.
        on PC1 you have to:

        1.check where is your php.ini file which is being used using phpinfo() in a php page.
        2.comment in extension=php_m ssql_dll.
        3.Download a ntwdblib.dll file from internet and copy it to C://wamp/php and C://wamp/apache2/bin.

        on PC2 you have to:

        1.enable remote connection.
        2.open configuration manager and enable TCP/IP port and enable all IP address under ip address column.Also put 1433 in TCP port row.
        3.check whether port 1433 is running sql service or any other by typing netstat -aov | find ":1433".Fro m here you will get PID of service which you can check in task manager.

        Now open router and open port forwarding.
        forward port 1433 to IP of PC2.
        And also check network configuration which is very important.
        Properly check DNS and gateway because these took my 1 day to make connection.
        Also turn off firewall.
        If you don't want to turn it off then configure firewall to allow sql service.
        I am also new in this area and if you can't get what I said please let me know.
        I hope this is enough for a remote connection.

        Comment

        Working...