msphpsql: Error code 0x2746

Please check the FAQ (frequently-asked questions) first. If you have other questions or something to report, please address the following (skipping questions might delay our responses):

PHP version
8.1 PHP SQLSRV or PDO_SQLSRV version
latest Microsoft ODBC Driver version
I tried with 17 and 18 SQL Server version
16 Client operating system
Ubuntu 22.04 Table schema

Problem description

I get Error code 0x2746 connecting to sql server. I’m using a docker environment (Laravel Sail)

Expected behavior and actual behavior
To connect to MssqlDatabase

Repro code or steps to reproduce

In my docker i installed following the documented procedure:

RUN curl -sS https://packages.microsoft.com/keys/microsoft.asc --output microsoft.asc RUN apt-key add microsoft.asc

RUN curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list > /etc/apt/sources.list.d/mssql-release.list RUN apt-get update

RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev mssql-tools

RUN pecl install sqlsrv RUN pecl install pdo_sqlsrv

RUN printf “; priority=20\nextension=sqlsrv.so\n” > /etc/php/8.1/mods-available/sqlsrv.ini RUN printf “; priority=30\nextension=pdo_sqlsrv.so\n” > /etc/php/8.1/mods-available/pdo_sqlsrv.ini`

In the past I had the same issue and I followed the workaround described here But now it’s not working.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@miquelangeld found a workaround for this. Turns out OpenSSL 3.0 changed the default behavior of SECLEVEL (you would think they would warn about this somewhere in capital case, as this is a breaking change essentially…) so you need to specify 0 now instead of 1. More info here: https://github.com/openssl/openssl/issues/17476

@clarumedia glad to hear it’s working fine now for you also. For me really the key, as mentioned, was the SECLEVEL=0 which did change on OpenSSL 3 (which Ubuntu 22.04 ships with) from what it was on previous versions.

Hopefully the notes here can help other people fix the issue.

@clarumedia have you tried using:

MinProtocol = TLSv1

Instead of

MinProtocol = TLSv1.0 (taken from the stackoverflow post)

I had issues with using the latest, but the first one did work fine. As for Ubuntu 22.04 the key for me has been to set the SECLEVEL to 0 instead of 1.

My setup is working fine right now with Ubuntu 22.04 using that config and ODBC 17. It was also working with ODBC 18 if specifying -C for sqlcmd so it will accept the cert, as cert validation works different in ODBC 18.