You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IIS部署Node.js连接MSSQL报错:数据源名称未找到且无默认驱动

解决IIS上Node.js连接MSSQL报错:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

在IIS上测试Node.js开发的MSSQL连接后端项目时,遇到错误:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

该项目在其他服务器运行正常,判断问题出在当前系统配置上,相关代码如下:

连接配置文件

const config = {
   server: "server name or IP address",
   port: SQL Port,
   user: "SQL Username",
   password: "sql password.",
   database: "sql database",
   options: {
     enableArithAbort: true,
   },
};

报错端点代码

const express = require("express");
const mssql = require("mssql/msnodesqlv8");
const config = require("./config");

const app = express();
//Customers //

app.get("/getstok", function (req, res) {
   mssql.connect(config, (error) => {
     if (error) {
       res.status(500).json({ error: "There was a problem with the MSSQL Connection", message: error.message });
     } else {
       const request = new mssql.Request();
       const query = `
       SELECT
       STOCKCARD ID
FROM IPLIKKARISIM
       `;
       request.query(query, (error, results) => {
         if (error) {
           console.error("Query error", error);
           res.status(500).json("SQL Query is not working properly.");
         } else {
           res.json(results.recordset);
         }
       });
     }
   });
});

app.listen(process.env.PORT);

解决方案

  • 安装对应版本的ODBC驱动:msnodesqlv8依赖Microsoft ODBC Driver for SQL Server,需根据系统和IIS应用池的位数(32/64位)安装对应版本。注意应用池是32位模式必须装32位驱动,64位则装64位。
  • 调整IIS应用池位数:打开IIS管理器,找到目标应用池,进入“高级设置”,设置“启用32位应用程序”为对应的值(和驱动位数一致)。
  • 指定驱动名称:在连接配置的options中添加driver字段,例如:
    options: {
      enableArithAbort: true,
      driver: '{ODBC Driver 17 for SQL Server}' // 替换为实际安装的驱动版本号
    }
    
  • 验证ODBC驱动存在:打开对应位数的ODBC数据源管理器(32位路径C:\Windows\SysWOW64\odbcad32.exe,64位C:\Windows\System32\odbcad32.exe),在“驱动程序”标签确认目标驱动已安装。
  • 检查应用池权限:确保应用池运行账户或连接配置中的SQL账户有访问目标SQL Server数据库的权限。

内容的提问来源于stack exchange,提问作者Samet Yılmaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 19:13:14