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

查看:105
本文介绍了ConnectionError:无法连接到本地主机: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:15000毫秒内未定义

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浏览器"上选择属性"
  3. 将启动类型"翻转为自动"
  4. 启动服务

成功!

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

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