ConnectionError: Failed to connect to localhost:undefined in 15000ms(ConnectionError:无法连接到 localhost:15000 毫秒内未定义)
问题描述
我正在使用 KnexJs 尝试连接到本地 Microsoft SQL Server Express.但是,使用以下配置,我收到错误消息.我已按照典型步骤进行操作,但仍然出现错误.
I am using KnexJs attempting to connect to a local Microsoft SQL Server Express. However, with the below configuration, I am getting an error. I've followed the typical steps, but I'm still getting the error.
我尝试过的:
- 为数据库设置 SQL Server 身份验证登录
- 在服务器上启用 SQL Server 身份验证
- 在服务器上启用 TCP/IP
- 重启 Windows 服务
- 通过 SQL Server Management Studio 重启 SQL Server
- 验证通过 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: 无法连接到 localhost:undefined in 15000ms
ConnectionError: Failed to connect to localhost:undefined in 15000ms
推荐答案
原来我还需要像这样启用SQL Server Browser windows服务:
It turns out that I also needed to enable the SQL Server Browser windows service like so:
- 导航到服务"
- 在SQL Server Browser"上选择属性"
- 将启动类型"改为自动"
- 启动服务
成功了!
这篇关于ConnectionError:无法连接到 localhost:15000 毫秒内未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ConnectionError:无法连接到 localhost:15000 毫秒内未定义


基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01