1

After sending many update requests on my webpage the database connection crashes and give me this error

Anyone can help ?

disable TSL1.0 and TSL1.1

Connectiong code

try {
    $dbh = new PDO("sqlsrv:Server=$Serve;Database=$name;ConnectionPooling=0",$user, $password;
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    //echo "Connection Established"
   }

   catch (PDOException $e) {
          print "Error:" . $e->getMessage() . "<br/>";

   }

NA

devpro
  • 16,184
  • 3
  • 27
  • 38
Ghaith Shaal
  • 11
  • 2
  • 2
  • 1
    Everything updated and "hotfixed" to latest and greatest? Update question with version numbers, ODBC drivers etc. – ficuscr Sep 04 '19 at 16:44

3 Answers3

1

I had a similar problem and the solution was to restart IIS.

For this, just go to Start and open Command Prompt as administrator. Then type iisreset and hit enter. After a few seconds, everything may be up and running again.

Hope it works for you and for others with similar issue.

0

Disclaimer; This is not "the solution", just the same behaviour and how to bypass it. Very little info on the matter and I have tried for a month to find what causes this.

We have the exact same behaviour on Windows Server 2019 (also 2016), IIS w PHP 7.3 and Azure SQL. (drivers 5.3 to 5.7.1 tested, PHP 7.1 to 7.3 tested)

This seem to be a connection issue, came with windows update and the code is valid but will not be able to connect from time to time. When it first crashes no connections will be made until IIS reloads fastcgi.

What server OS is this on? (On Linux we do not seem to have this problem)

Have no idea but seem to be the driver and OS related, if we specify ODBC in the connection string it does not seem to crash but it does not handle all charsets out of the box with ODBC driver. You can fix that programatically though.

ODBC utf-8: Unable to retrieve UTF-8 accented characters from Access via PDO_ODBC

TLS SSL/TLS 1.2 Connection Issues - PHP/SQLSRV

  • Thanks for getting back to me, I am using IIS , PHP 7.3, SQL server 2016 and I tried one of the articles you attached, updated the ODBC drivers that did not support TLS 1.2 but the issue still there can you tell me what drivers should I have installed typically for the webserver – Ghaith Shaal Jan 06 '20 at 11:37
  • Hello, here is what is working for us (4 days with no connection errors!), Odbc driver version 17 (2017.173.01.01), SQL driver 5.6 from WebPlatform Installer 5.1, PHP 7.3.7 also form WPI 5.1. All x64. No beta drivers or test drivers. If I was to guess I think that the IIS server and the remote sql server cannot negotiate protocol or encryption after a while. On Windows Servr 2016/2019 we usually run fine until load increase, then the errors start. – Trond V Jan 10 '20 at 13:07
  • Thanks for getting back to me Trond, I have changed the connection string to $dbh = new PDO("odbc:Driver={ODBC driver 17 for SQL Server};Server=$Serve;Database=$name;ConnectionPooling=0",$user, $password) and I haven't faced the issue sicne , do you have any insights that can help me understand what is going on ? – Ghaith Shaal Jan 10 '20 at 14:02
0

we downgraded to Windows Server 2012 R2 and now it seems like the issues are gone (we run Azure and AWS instances). Azure SQL seem to be closest related to sql server 2014.

For the Windows 2012 servers I did install the PHP 7.3.7 package that came with "web platform installer" and also the SQl Server driver 5.6 for that PHP version.

Don't think it is neccessary or needed for the SQL connections but have added curl and ssl cacert path in php.ini (it is needed for pushing data to AWS S3 though).

I also tested IIScrypto to adjust registry settings to use either TLS 1.2, all TLS, different cyphers, the solutions in the above links but no success.

The problems started with windows update or possibly a sql server update and it is intermittent making it hard to find out. Clearly related to communication but not reproducable "on demand".

We are moving the solution to a Linux platform as soon as the rest of the legacy (.asp/.aspx) scripts are converted to php.

My best bet is to use the latest php and latest sql driver from "web platform installer", also update to latest ODBC driver if you need but we are running now with the version 17 (2017.173.01.01) 2/14/2019 that came with the Windows server 2012R2 image.

  • Do you think downloading this driver might solve the issue https://www.microsoft.com/en-us/download/details.aspx?id=56730 – Ghaith Shaal Jan 09 '20 at 12:09
  • I may be wrong but you are normally using the ODBC or the SQLServer driver with PHP. I see there are some references to OLEDB but I have never used it with PHP. – Trond V Jan 13 '20 at 12:28
  • We have the same error reported (which started happening all of a sudden) in Azure, with SQL Server SaaS, PHP 7.2, SQL PHP driver 5.7.1, ODBC 2017.173.01.01 (from 14th Feb, 2019). We uploaded the ODBC to 2017.174.02.01 (that is the v17.4.2.1) so we'll see if that stops it. Although, so far we had it on only 2 days, and even the 2nd time it went away on its own, so who knows what fixes it and if it does anything at all – userfuser Jan 25 '20 at 12:10
  • IMO this is a Microsoft OS or Azure issue, we really dont have much to go by. We saw the same today and we are just moving to Linux as soon as possible. I am considering the latest drivers but this may be related to Schannel / SSL (Not a windows server specialist though). – Trond V Jan 27 '20 at 12:45