-
Notifications
You must be signed in to change notification settings - Fork 475
Description
Expected behaviour:
Using module mssql/msnodesqlv8
. When using Windows, creating new connection pool, the driver is always defaulted to SQL Server Native Client 11.0
. Expected to have connections established successfully.
Actual behaviour:
In a fresh Windows 10 machine, installing SQL Server 2022 Developer edition, the ODBC driver SQL Server Native Client 11.0
is no longer included, as Microsoft does not recommend using the driver for new application development. Source https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/installing-sql-server-native-client?view=sql-server-ver16.
Therefore on connect, we'll receive error [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
.
Workaround:
Current work around for now is applying beforeConnect
method to override the driver to a supported ones such as ODBC Driver 17 for SQL Server
.
import sql from "mssql/msnodesqlv8";
const config = {
user: process.env["SQLUsername"],
password: process.env["SQLPassword"],
server: process.env["SQLServer"],
database: process.env["SQLDatabase"],
options: {
encrypt: false, // set to true for Azure SQL
trustedConnection: true, // set to true if use Windows authentication for local db
},
beforeConnect: function (bcConfig) {
// Modify the connection options here
/** The Driver SQL Server Native Client has been removed from SQL Server 2022.
* Source https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/installing-sql-server-native-client?view=sql-server-ver16
* ODBC Driver 17 for SQL Server is tested working well with SQL Server 2019 & 2022 */
bcConfig.conn_str = bcConfig.conn_str.replace("SQL Server Native Client 11.0", "ODBC Driver 17 for SQL Server");
}
};
let pool = new sql.ConnectionPool(config);
My github repo reference.
Software versions
- NodeJS: v18.14.2
- node-mssql: ^9.1.1
- msnodesqlv8: ^3.0.1
- SQL Server: SQL Server 2022
- Windows 11 Enterprise 64-bit operating system, x64-based processor