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

SQL Server登录失败求助:执行查询提示用户登录失败

求助:SQL Server 连接报错 "Login failed for user ' '"

我正在为个人网站搭建数据库,操作时始终遇到登录失败错误:

Error executing query: Login failed for user ' '

目前已确认以下信息:

  • 服务器运行正常,单独的测试文件能验证连接成功
  • SQL Server 已设置为混合身份验证模式
  • 其他配置未发现明显异常

附上相关代码文件及配置,希望能定位问题所在:

dbConfig.js

const config = {
    name: 'ArtPortfolio',
    password: 'kierrarg',
    server: 'DESKTOP-DC3RG3A',
    database: 'Contact',
    options: {
        trustServerCertificate: true,
        enableArithAbort: true,
    },
    port: 1433
}

module.exports = config;

dbOperation.js

const config = require('./dbConfig'),
sql = require('mssql');

const getContact = async() => {
    try {
        let pool = await sql.connect(config);
        let contact = pool.request().query("SELECT * from Contact")
        console.log(contact);
        return contact;
    }
    catch(error) {
        console.log('Error executing query:', error.message);
    }
}

module.exports = {
    getContact
}

server.js

const express = require('express'),
dbOperation = require('./dbfiles/dbOperation'),
cors = require('cors');

const API_PORT = process.env.PORT || 5000;
const app = express();

app.use(cors());

app.get('/api', function(req, res) {
    console.log('called');
    res.send({result: 'hellloooo'})
})

app.get('/quit', function(req, res) {
    console.log('called');
    res.send({result: 'byeeeeee'})
})

dbOperation.getContact().then(res => {
    console.log(res);
})

app.listen(API_PORT, () => console.log(`Listening on port ${API_PORT}`));

package.json 新增配置

"proxy": "http://localhost:5000",

"server": "nodemon server.js",

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 03:02:14