mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 06:46:00 +00:00
#183 fix msnodesql driver problem
This commit is contained in:
@@ -43,22 +43,38 @@ function extractNativeColumns(meta) {
|
||||
return res;
|
||||
}
|
||||
|
||||
async function nativeConnect({ server, port, user, password, database, authType }) {
|
||||
async function connectWithDriver({ server, port, user, password, database, authType }, driver) {
|
||||
let connectionString = `server=${server}`;
|
||||
if (port && !server.includes('\\')) connectionString += `,${port}`;
|
||||
connectionString += ';Driver={SQL Server Native Client 11.0}';
|
||||
connectionString += `;Driver={${driver}}`;
|
||||
if (authType == 'sspi') connectionString += ';Trusted_Connection=Yes';
|
||||
else connectionString += `;UID=${user};PWD=${password}`;
|
||||
if (database) connectionString += `;Database=${database}`;
|
||||
return new Promise((resolve, reject) => {
|
||||
msnodesqlv8.open(connectionString, (err, conn) => {
|
||||
if (err) reject(err);
|
||||
conn._connectionType = 'msnodesqlv8';
|
||||
resolve(conn);
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
conn._connectionType = 'msnodesqlv8';
|
||||
resolve(conn);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function nativeConnect(connection) {
|
||||
const drivers = ['ODBC Driver 17 for SQL Server', 'SQL Server Native Client 11.0'];
|
||||
for (let i = 0; i < drivers.length; i += 1) {
|
||||
try {
|
||||
const res = await connectWithDriver(connection, drivers[i]);
|
||||
return res;
|
||||
} catch (err) {
|
||||
if (err.message.includes('[ODBC Driver Manager]') && i < drivers.length - 1) continue;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function nativeQueryCore(pool, sql, options) {
|
||||
if (sql == null) {
|
||||
return Promise.resolve({
|
||||
|
||||
Reference in New Issue
Block a user