From bfea77c56bb52b4d6af3ae233593c6beabed89b1 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 28 Feb 2022 18:00:14 +0100 Subject: [PATCH] mssql tedious fix #236 --- docker-compose.yaml | 16 ++++++++++++ .../src/backend/tediousDriver.js | 25 +++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 65729628..97ac43c6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,6 +5,7 @@ services: dbgate: build: docker # image: dbgate/dbgate:beta-alpine + # image: dbgate/dbgate:beta restart: always ports: - 3100:3000 @@ -17,6 +18,13 @@ services: environment: WEB_ROOT: /dbgate + # CONNECTIONS: mssql + # LABEL_mssql: MS Sql + # SERVER_mssql: mssql + # USER_mssql: sa + # PORT_mssql: 1433 + # PASSWORD_mssql: Pwd2020Db + # ENGINE_mssql: mssql@dbgate-plugin-mssql proxy: # image: nginx build: test/nginx @@ -32,6 +40,14 @@ services: # FILE_sqlite: /mnt/sqt/Chinook.db # ENGINE_sqlite: sqlite@dbgate-plugin-sqlite + # mssql: + # image: mcr.microsoft.com/mssql/server + # restart: always + # environment: + # - ACCEPT_EULA=Y + # - SA_PASSWORD=Pwd2020Db + # - MSSQL_PID=Express + volumes: dbgate-data: driver: local \ No newline at end of file diff --git a/plugins/dbgate-plugin-mssql/src/backend/tediousDriver.js b/plugins/dbgate-plugin-mssql/src/backend/tediousDriver.js index a02c324b..e65bbe5d 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/tediousDriver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/tediousDriver.js @@ -24,6 +24,20 @@ function extractTediousColumns(columns, addDriverNativeColumn = false) { async function tediousConnect({ server, port, user, password, database, ssl }) { return new Promise((resolve, reject) => { + const connectionOptions = { + encrypt: !!ssl, + cryptoCredentialsDetails: ssl ? _.pick(ssl, ['ca', 'cert', 'key']) : undefined, + trustServerCertificate: ssl ? (!ssl.ca && !ssl.cert && !ssl.key ? true : ssl.rejectUnauthorized) : undefined, + enableArithAbort: true, + validateBulkLoadParameters: false, + requestTimeout: 1000 * 3600, + port: port ? parseInt(port) : undefined, + }; + + if (database) { + connectionOptions.database = database; + } + const connection = new tedious.Connection({ server, @@ -35,16 +49,7 @@ async function tediousConnect({ server, port, user, password, database, ssl }) { }, }, - options: { - encrypt: !!ssl, - cryptoCredentialsDetails: ssl ? _.pick(ssl, ['ca', 'cert', 'key']) : undefined, - trustServerCertificate: ssl ? (!ssl.ca && !ssl.cert && !ssl.key ? true : ssl.rejectUnauthorized) : undefined, - enableArithAbort: true, - validateBulkLoadParameters: false, - requestTimeout: 1000 * 3600, - database, - port: port ? parseInt(port) : undefined, - }, + options: connectionOptions, }); connection.on('connect', function (err) { if (err) {