ConnectionError:无法连接到 localhost:15000 毫秒内未定义 [英] ConnectionError: Failed to connect to localhost:undefined in 15000ms

查看:78
本文介绍了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.

我尝试过的:

  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: 无法连接到 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:

  1. 导航到服务"
  2. 在SQL Server Browser"上选择属性"
  3. 将启动类型"改为自动"
  4. 启动服务

成功了!

这篇关于ConnectionError:无法连接到 localhost:15000 毫秒内未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆