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

Azure SQL Database登录失败求助:本地函数连接报错

Azure SQL Database 登录失败问题排查与解决

错误信息

originalError: ConnectionError: Login failed for user 'CloudSAa64a1c9'.
at Login7TokenHandler.onErrorMessage (/Users/yasindalkilic/Desktop/jsfunc/node_modules/tedious/lib/token/handler.js:186:19)
at Readable. (/Users/yasindalkilic/Desktop/jsfunc/node_modules/tedious/lib/token/token-stream-parser.js:19:33)

问题代码

const config = {
    user: 'CloudSAa64a1cd9', 
    password: '', 
    server: 'boatsaily.database.windows.net', 
    database: 'BoatSaily',
    options: {
      encrypt: true, 
      trustServerCertificate: false, 
      trustedConnection: true
    }};
const sql = require('mssql');

async function fetchData() {
    try {
      let pool = await sql.connect(config);
      let result = await pool.request().query('SELECT * FROM dbo.Kisiler');
      console.log(result.recordset);
      // Bağlantıyı kapat
      pool.close();
    } catch (err) {
      console.error('Hata:', err);
    }
}

fetchData();

解决步骤

  • 修正用户名拼写:错误提示中的用户名是CloudSAa64a1c9,但代码里写成了CloudSAa64a1cd9(多了一个d),这是登录失败的直接原因,需完全匹配Azure门户中的管理员用户名。
  • 补全数据库密码:代码内password字段为空,必须填写Azure SQL服务器管理员的正确密码。
  • 禁用可信连接:Azure SQL不支持Windows集成身份验证,需将options中的trustedConnection改为false,或直接删除该配置项。
  • 添加本地IP到防火墙白名单:登录Azure门户,进入对应SQL服务器的「防火墙和虚拟网络」设置,将当前本地机器的公网IP添加到允许访问的IP列表中。
  • 校验服务器与数据库名称:确认server和database字段的拼写与Azure门户中的信息完全一致,避免因大小写或字符错误导致连接失败。

内容的提问来源于stack exchange,提问作者yasin89

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 12:27:13