none
Connecting Error with sqlsrv_connect() and/or PDO_SQLSRV

    Question

  • Good evening,

    i got following problem:

    Since few days i installed a driverpaket which is including "php_pdo_sqlsrv_53_ts_vc9.dll" and "hp_sqlsrv_53_ts_vc9.dll".

    I activated them in php.ini.

    I also installed SQL Server Native Client 10.0.

    Restarted Apache (wich the XAMPP-Panel) and until now it worked well.

    If i open the "website" on my local computer at home i got this error: 

    Array
    (
        [0] => Array
            (
                [0] => 08001
                [SQLSTATE] => 08001
                [1] => -1
                [code] => -1
                [2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. 
                [message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. 
            )
    
        [1] => Array
            (
                [0] => HYT00
                [SQLSTATE] => HYT00
                [1] => 0
                [code] => 0
                [2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
                [message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
            )
    
        [2] => Array
            (
                [0] => 08001
                [SQLSTATE] => 08001
                [1] => -1
                [code] => -1
                [2] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. 
    Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
                [message] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. 
    Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
            )
    
    )


    I am really sure that i used the correct connection-data and the MSSQL-Server at the Root-Server also works fine.
    A friend conencted with mssql_connect() to this Server, also worked fine.
    mssql_connect() is depricated as far as i know and i want to use sqlsrv_connect(), and the PDo-Version later on.

    Anyone has any idea what i should do to solve this problem?

    Thank you very much.

    VirtualSheldon :) 

    Monday, November 28, 2011 7:15 PM

Answers

  • Hi,

    Can you please tell which kind of connection option you want to login? Windows authentication or sql server authentication?


    It sounds like you try windows authentication because when the server can be reached and sql server user and password you validated on the server than it must work from your home computer (normally).

    When you really try to connect with windows authentication then it depends if your home computer is on the same domain like your server. Because kerberos authentication cannot be used when your home computer and the server are in different domains with no trust or your client and the server is separated through a firewall which prevents kerberos.

    In this case connect on the server and create a sql server account. When you have done this connect this way - UID and PWD indicated sql server authentication - windows authentication is used when these parameters are not used.:

    $serverName = "COMPUTERNAME\SQLEXPRESS";
    $connectionInfo = array(
    'Database' => 'YourDatabase',
    'UID' => 'YourUser',
    'PWD' => 'YourPassword');
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    Regards

    Saturday, December 03, 2011 1:18 PM

All replies

  • There are a few things that jump out here...

    If you are using Apache, you should be a using a build of PHP that was compiled with the VC6 compiler. (See the "Which version do I choose?" section this page for more info: http://windows.php.net/).

    The build of the sqlsrv driver that you use should match the build of PHP that you are using (VC6 or VC9).

    So, 1) make sure you are using a VC6 build of PHP with Apache, and 2) use VC6 builds of the sqlsrv drivers.

    Hope that helps.

    -Brian


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan
    Monday, November 28, 2011 9:06 PM
    Moderator
  • Hmm, it's funny, because i just installed XAMPP 1.7.7 and it includes PHP 5.3.8 VC9.

    (If i try to activate VC6, PHP tells me to use the other compiled driver.)

    As far as have seen, there is just a VC9 compiled Version of te new 5.3.8. Latest Version of VC6 compiled one is PHP 5.2.1.

    To use my namespaces and other new features i am used to use PHP 5.3.8.

    Anything i did understand wrong?^^

     

    If there is no other way, i will uninstall current PHP and install VC6 compiled one with 5.2.1.

     

    Thanks alot

    VirtualSheldon :)

    Tuesday, November 29, 2011 1:57 AM
  • That is strange. The windows.php.net site very clearly says that you should use a VC6 build of PHP when using Apache. (And I think you are right that 5.3.8 doesn't have a VC6 build.) But, perhaps I'm barking up the wrong tree.

    Are you sure the server name is correct? If you are using SQL Server Express, the server name will likey be "servername\sqlexpress". Can you connect to the server using SQL Server Management Studio? (Those are the things I'd start looking at next.)

    -Brian

     


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan
    Tuesday, November 29, 2011 4:37 AM
    Moderator
  • A friend told me that he was able to connect to this server with the data i have also used to connect.

    I wish i could try also these data by connecting with "SQL Server Management Studio", but i don't have this Management Studio on my computer.

    If i install this one and restart Apache, Apache isn't able to start anymore. Apache tells me, Port is already in user.

    And PorcessID 4 needs this port, just as long as the Studio is on my computer.

    That's the reason, why i am scared to install a serve on my home computer again :).

    Any solution for this mayhe :D?

     

    Lovely Greatings :P

    VirtualSheldon

    Tuesday, November 29, 2011 11:57 AM
  • Hi,

    You should install the SQL Server Management Studio to verify connectivity to the server. You can do so by using the SQL Server Express installer, but just selecting the Management Tools (Basic) option when installing. It very much looks like a connection error, so it would be good to rule this out first.

     

    Thanks,

    Jonathan


    This posting is provided 'AS IS' with no warranties, and confers no rights.
    Tuesday, November 29, 2011 6:21 PM
  • So, now i installed Micrsofot Management Studio 2008.

    I used data first at Root-Server ( where SQL-Server ist installed ) => it worked well.

    Then i used Microsoft Management Studio 2008 on my home computer, same data, it failed and this error appeared:


    Just one question now. What exactly do i enter for Server-Instance?
    At Root-Server i wrote: computername\sqlpexpress.

    At home computer don't need i any addional information like IP-Adress to add?

    Example IP\computername\sqlexpress? 

    Atleast i tried this one but still no success :(

    Any idea what i should do now?

     

    Thanks alot

    Sheldon


    Tuesday, November 29, 2011 11:03 PM
  • Sheldon,

    Change your connection string to:

    85.214.249.22\SQLEXPRESS

    You don't need the computer name in there. :)

    Thanks,

    Jonahtan


    This posting is provided 'AS IS' with no warranties, and confers no rights.
    Wednesday, November 30, 2011 12:11 AM
  • So now i tried again with IP\SQLEXPRESS and other options, but no chance.

    Username and Password are correct for sure, i tried at root server.

    I connect at Root-Server with COMPUTERNAME\SQLEXPRESS

    At home computer i used all kinds of server-instances, no chance anyway :/.

     

    Firewall is also deactivated.

    Maybe there is a problem with my rights, because i am just second user at this MSSQL-Server.

    Anything my friend should change at these options?

     

    EDIT: 

    I guess the necessary ports 1433 and/or 1434 are blocked and i am not allowed to open them.

    Anyway i try installing the complete Server on my home-computer.

     

    But even if i am able to connect to the server now, there is another problem:

    If i connect with odbc,pdo_odbc,pdo_... . How do i connect to MSSQL-Server if webspace will be on Webspace later on? I am also not allowed to install the necessary driver.

    What is the easiest and most modern way to connect?

    Any hints?

     

     

    Thank you very much.

    Sheldon




    Wednesday, November 30, 2011 10:37 AM
  • Hi Sheldon,

    I suspect you do not have TCP connections enabled - make sure they are in the SQL Server Management Studio.

    With regards to your second ask:
    We support connections to SQL Server from PHP via the SQLSRV and PDO_SQLSRV extensions. These also both require the SQL Server Native Access Client (SNAC) ODBC Driver to function. If you are not able to install either the extensions or the SNAC Driver, you will not be able to use these. Even if you want to connect to SQL Server using the generic PHP_ODBC and PDO_ODBC extensions, you will require the SNAC driver to be installed.

    Thanks,

    Jonathan


    This posting is provided 'AS IS' with no warranties, and confers no rights.
    Wednesday, November 30, 2011 9:14 PM
  • Hi,

    Can you please tell which kind of connection option you want to login? Windows authentication or sql server authentication?


    It sounds like you try windows authentication because when the server can be reached and sql server user and password you validated on the server than it must work from your home computer (normally).

    When you really try to connect with windows authentication then it depends if your home computer is on the same domain like your server. Because kerberos authentication cannot be used when your home computer and the server are in different domains with no trust or your client and the server is separated through a firewall which prevents kerberos.

    In this case connect on the server and create a sql server account. When you have done this connect this way - UID and PWD indicated sql server authentication - windows authentication is used when these parameters are not used.:

    $serverName = "COMPUTERNAME\SQLEXPRESS";
    $connectionInfo = array(
    'Database' => 'YourDatabase',
    'UID' => 'YourUser',
    'PWD' => 'YourPassword');
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    Regards

    Saturday, December 03, 2011 1:18 PM
  • Hi Sheldon,

    Sqltechi has some good pointers for you to follow - have you had a chance to try them out?

    Thanks,

    Jonahtan


    This posting is provided 'AS IS' with no warranties, and confers no rights.
    Tuesday, December 06, 2011 5:09 PM