Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const config = {
trustedConnection: true, // Set to true if using Windows Authentication
trustServerCertificate: true, // Set to true if using self-signed certificates
},
driver: "msnodesqlv8", // Required if using Windows Authentication
// driver: "ODBC Driver 18 for SQL Server", // Uncomment to use specific driver
};

(async () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/msnodesqlv8/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ConnectionError = require('../error/connection-error')
const { platform } = require('node:os')
const { buildConnectionString } = require('@tediousjs/connection-string')

const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'
const DEFAULT_CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'

class ConnectionPool extends BaseConnectionPool {
_poolCreate () {
Expand All @@ -23,7 +23,7 @@ class ConnectionPool extends BaseConnectionPool {

if (!this.config.connectionString) {
cfg.conn_str = buildConnectionString({
Driver: CONNECTION_DRIVER,
Driver: this.config.driver && this.config.driver !== 'msnodesqlv8' ? this.config.driver : DEFAULT_CONNECTION_DRIVER,
Server: this.config.options.instanceName ? `${this.config.server}\\${this.config.options.instanceName}` : `${this.config.server},${this.config.port}`,
Database: this.config.database,
Uid: this.config.user,
Expand Down
35 changes: 35 additions & 0 deletions test/msnodesqlv8/msnodesqlv8.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ describe('msnodesqlv8', function () {
after(() => sql.close())
})

describe('config().driver tests', function () {
it('cfg.driver is undefined', done => {
const cfg = config()
cfg.driver = undefined
sql.connect(cfg, done)
})

// Specifically for Windows
it('cfg.driver is SQL Server Native Client 11.0', done => {
const cfg = config()
cfg.driver = 'SQL Server Native Client 11.0'
sql.connect(cfg, done)
})

it('cfg.driver is invalid', done => {
const cfg = config()
cfg.driver = 'aaTESTING1234'

sql.connect(cfg, function (err) {
if (err) {
// Specifically for Windows
if (err.message === '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified') {
return done()
}

return done(new Error('Incorrect error message shown'))
}

return done(new Error('No error message shown'))
})
})

afterEach(() => sql.close())
})

after('cleanup', done =>
sql.connect(config(), function (err) {
if (err) return done(err)
Expand Down