Okay
  Public Ticket #3593724
Connect to SQL Server
Closed

Comments

  •  1
    Tymek started the conversation

    Hi,

    I have WordPress + WPdatatables on my internal intranet.
    The server is a virtual machine + Linux Ubuntu 22.04.
    The SQL server is the second virtual machine of Windows Server 2016. When I try to connect wpdatatables to the SQL database, I get the following error:
    wpDataTables could not connect to mssql server. mssql said: There was a problem with your SQL connection - could not find driver

    T.

  • Giovanni replied

    Same needs.

  •  1,846
    Miloš replied

    Hello,

    First, please check if you have the following drivers installed on your WordPress Hosting server, and activated :

    3838527468.png

    These drivers need to be installed and activated on the server where your WordPress website is. 

    After you install and activate those drivers, it should work fine.

    If you're not sure how to install the drivers, please reach out to your hosting provider ( or on a LocalHost installation, you would need to find some tutorials online on the subject how to install these drivers from the screenshot).

    The server to which wpDataTables is connecting has its own method of establishing the connection, and we're using PHPs logic of connecting to separate connections. 

    -

    Then, when you have these installed, you need to contact the support of your remote server and ask them for instructions and details what is needed to be input in order to connect,

    such as connection name, host, port, user, password, etc;

    In the end, try to Test the DB Connection in our Plugin, and see if you get any errors.

    -

    If there are errors your server returns, those are returned by the server, 

    and only displayed by wpDataTables -

     there is no additional log within wpDataTables that would distinctively show you what's behind the error.

    I hope this helps.


    Some additional useful informations to know for MSSQL type of connection specifically;

    I searched a bit more online for general MSSQL Drivers to try and determine what should be installed on your WP Hosting Server, and i found this Post from Stack Overflow, where a User posted a Screenshot of all the Drivers he had to enable.

    He specifically highlighted these two ( which i did not see you confirmed from your end so far), the "sqlsrv" and "pdo_sqlsrv".

    1187422456.png

    Can you please check again with your WordPress Hosting Provider, do they have those two Drivers installed and activated?


    If the DB is using SSL, for MySQL, you should add mysqli_set_ssl after mysqli_connect in this file:

    wp-content/plugins/wpdatatables/source/class.sql.php on line 47

    You can read more about this on stack overflow.

    For other SQL engines, you should use the PDO extension, so if it's SQL, you can take a look at this link.



    And one final advice, this is from one of our Users, who had an issue about SSL for their MSSQL Connection.

    This is what he said solved it for him :

    In the meantime I was able to solve the connection issue and bypass the SSL by modifying the connection string to SQL Server in 

    .../wpdatatables/source/class.connection.php.

    (for the SQL Server driver) and adding no encryption and trusting server certificates (TrustServerCertificate = true; Encrypt = false).

    .......

    switch ($vendor) {
                case (self::$MSSQL):
                    if (isset($driver) && $driver == 'sqlsrv') {
                        return new PDOSql($vendor, "$driver:Server=$host,$port;Database=$database; TrustServerCertificate=True; Encrypt=false", $user, $password);
                    }

    ..............

    I hope that helps.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Tymek replied

    Thanks for reply. 

    Driver installed. The plugin tries to connect to the database, but there is an error.

    wpDataTables could not connect to mssql server. mssql said: There was a problem with your SQL connection - SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain was issued by an authority that is not trusted.

  •  1
    Tymek replied

    I didn't read it to the end.

    Works! Many Thanks!

    switch ($vendor) {
                case (self::$MSSQL):
                    if (isset($driver) && $driver == 'sqlsrv') {
                        return new PDOSql($vendor, "$driver:Server=$host,$port;Database=$database; TrustServerCertificate=True; Encrypt=false", $user, $password);
                    }

  •   Miloš replied privately