Skip to content

Commit

Permalink
Multiple MSSQL driver improvements (#1396)
Browse files Browse the repository at this point in the history
* Use Microsoft recommended system table to get a list of databases

* Throw database configuration errors rather than retrying

* Set default connection timeout to 15 - same as the tedious driver

* Add trustServerCertificate in connection.schema.json

* Add trustServerCertificate in driver.ts
  • Loading branch information
fzhem authored Nov 15, 2024
1 parent 9e7da20 commit 2429c6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/driver.mssql/connection.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"connectionTimeout": {
"title": "Connection Timeout",
"type": "integer",
"minimum": 0
"minimum": 0,
"default": 15
},
"mssqlOptions": {
"type": "object",
Expand All @@ -68,6 +69,10 @@
"type": "boolean",
"default": true
},
"trustServerCertificate": {
"type": "boolean",
"default": false
},
"tdsVersion": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -221,4 +226,4 @@
"required": [
"connectionMethod"
]
}
}
7 changes: 6 additions & 1 deletion packages/driver.mssql/src/ls/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class MSSQL extends AbstractDriver<MSSQLLib.ConnectionPool, any>
return this.connection;
}

const { encrypt, ...mssqlOptions }: any = this.credentials.mssqlOptions || { encrypt: true };
const { encrypt, trustServerCertificate, ...mssqlOptions }: any = this.credentials.mssqlOptions || { encrypt: true };

let encryptAttempt = typeof encrypt !== 'undefined'
? encrypt : true;
Expand All @@ -42,13 +42,18 @@ export default class MSSQL extends AbstractDriver<MSSQLLib.ConnectionPool, any>
options: {
...((mssqlOptions || {}).options || {}),
encrypt: encryptAttempt,
trustServerCertificate: trustServerCertificate,
},
});

await new Promise((resolve, reject) => {
pool.on('error', reject);
pool.connect().then(resolve).catch(reject);
}).catch(e => {
// The errors below are relevant to database configuration
if (e.code === "ESOCKET" || e.code === "ELOGIN" || e.code === "EINSTLOOKUP") {
throw e;
}
if (this.retryCount === 0) {
this.retryCount++;
return this.open(!encryptAttempt)
Expand Down
2 changes: 1 addition & 1 deletion packages/driver.mssql/src/ls/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ SELECT name AS label,
name AS "database",
'${ContextValue.DATABASE}' AS "type",
'database' AS "detail"
FROM MASTER.dbo.sysdatabases
FROM sys.databases
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb')
`;
export const searchTables: IBaseQueries['searchTables'] = queryFactory`
Expand Down

0 comments on commit 2429c6f

Please sign in to comment.