Troubleshooting PHP and SQL Server

SQL Server Connection issues:

Prerequisite:   Put  the sqlsrv_errors() code snippet found elsewhere on this site, into your code, immediately following your connection statements, and run your PHP code again.   If you get any of the following connection errors, follow the advice given.ERROR [IM002]

  • [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    • This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
    • Go to the Microsoft ODBC Driver 11 for SQL Server web page, and download the ODBC version11 drivers
  • SQLSTATE ERROR: HYT00 [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
    • Open SQL Server Configuration Manager
      • Under SQL Server Network Configuration, Protocols for SQLEXPRESS
      • Enable TCP/IP

EnableIPOnLocalHost

  • Double-Click on TCP/IP
  • Select the IP Addresses Tab
  • Set TCP Port to 1433

Configure Port 1433

 

  • SQLSTATE ERROR: 08001 [Microsoft][ODBC Driver 11 for SQL Server]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.
    • Same solution as SQLSTATE ERROR: HYT00

 

  • SQLSTATE ERROR: 08S01 code: 10054 message: [Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote host.
    • Same solution as  SQLSTATE ERROR: HYT00

 

  • SQLSTATE ERROR: 08S01 code: 10054 message: [Microsoft][ODBC Driver 11 for SQL Server]Communication link failure
    • Same solution as SQLSTATE ERROR: HYT00

 

  • SQLSTATE ERROR: 01000 code: 5701 message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server Changed database context to ‘DATABASENAME’.
    • This error is a little tricky.    You can read more about it at https://support.microsoft.com/en-us/kb/143339.Although this is returned by Microsoft, it does not mean that the connection is not working.You can either ignore it in your PHP code, ignore all 5701 and 5703 errors, or you can prevent it from being seen by PHPTo prevent it,  you must know which IP connection is being used by the client, and then enable that connection in SQL Server Configuration Manager.   In this example, I am using localhost, so I will use the IP address 127.0.0.1, but your installation may be different.  In any case,  to prevent it, you will always want to enable the IP bound to the hardware device that your clients are attaching to.
    • Open SQL Server Configuration ManagerUnder SQL Server Network Configuration
    • Locate the IP Address which is 127.0.0.1
    • Change the value to Enabled = Yes

EnableIPOnLocalHost

  • SQLSTATE ERROR: 01000 code: 5703 message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Changed language setting to us_english. Resource id #x
    • Same solution as SQLSTATE ERROR: 01000 code: 5701

 

  • SQLSTATE ERROR: 01000code: 5701message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Changed database context to  ‘DATABASENAME’.SQLSTATE ERROR: 01000code: 5703message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Changed language setting to us_english
    • Same solution as SQLSTATE ERROR: 01000 code: 5701

 

Leave a Reply