gpt4 book ai didi

sql-server - 连接错误: Failed to connect to localhost:undefined in 15000ms

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:20 25 4
gpt4 key购买 nike

我正在使用 KnexJs 尝试连接到本地 Microsoft SQL Server Express。但是,使用以下配置时,我收到错误。我已按照典型步骤操作,但仍然收到错误。

我尝试过的:

  1. 为数据库设置 SQL Server 身份验证登录
  2. 在服务器上启用 SQL Server 身份验证
  3. 在服务器上启用 TCP/IP
  4. 重新启动 Windows 服务
  5. 通过 SQL Server Management Studio 重新启动 SQL Server
  6. 验证是否能够通过 SQL Server Management Studio 登录

配置/查询代码:

    let mssql = knex({
client: 'mssql',
connection: {
host: 'localhost\\sqlexpress',
user: 'test',
password: 'test',
database: 'AdventureWorks2017',
// port:1433,
// options: {
// trustedConnection: true
// },
useNullAsDefault: true
}
});

mssql.raw('select 1 as result').then(function (result) {
console.log('result');
console.log(result);
mainWindow.webContents.send('testConnectionResponse', result === 1);
event.sender.send('testConnectionResponse', result === 1);
}).catch(function (err) {
console.log(err);
mainWindow.webContents.send('query-error', err);
}).finally(() => {
mssql.destroy();
});

错误:

ConnectionError: Failed to connect to localhost:undefined in 15000ms

最佳答案

事实证明,我还需要启用 SQL Server Browser Windows 服务,如下所示:

  1. 导航至“服务”
  2. 在“SQL Server 浏览器”上选择“属性”
  3. 将“启动类型”切换为“自动”
  4. 启动服务

成功!

关于sql-server - 连接错误: Failed to connect to localhost:undefined in 15000ms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49185969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com