无法使用 Node.js 和 Tedious 连接到 SQL Server [英] Cannot connect to SQL Server with Node.js and Tedious

查看:33
本文介绍了无法使用 Node.js 和 Tedious 连接到 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 Node.js 和 Tedioius 连接到本地 SQL Server 实例时,出现此错误:

When I try to use Node.js and Tedioius to connect to a local SQL Server instance I get this error:

{ [ConnectionError: Failed to connect to XXXXX:1433 - connect ECONNREFUSED]
  name: 'ConnectionError',
  message: 'Failed to connect to XXXXX:1433 - connect ECONNREFUSED',
  code: 'ESOCKET' }

这是我的连接对象:

var config = {
  userName: 'username',
  password: 'password',
  server: 'XXXXX',

  options: {
    database: 'databasename',
    instancename: 'SQLEXPRESS'
  }
};

我已检查并根据配置管理器启用了 TCP/IP 并在端口 1443 上进行广播.SQL Server Browser 服务也在运行,如果没有,我读到可能会导致此类问题.我已经禁用了我的防病毒软件和防火墙,但这也没有帮助.

I have checked and TCP/IP is enabled and broadcasting on port 1443 according to Configuration Manager. The SQL Server Browser service is also running, which I read may be causing this type of issue if not. I have disabled my antivirus and firewall and that hasn't helped either.

有什么见解吗?

推荐答案

所以我猜测会发生的是,即使 Tedious 允许您在 'options' 中包含实例名称,它要么不使用它,要么不能使用它因为它需要被使用.在做了一些研究之后,应该发生的事情是,当您为 SQL Server 提供实例名称时,它会将您从端口 1433 重定向到它用于该实例的动态端口.我不知道它使用的是动态端口,但是如果您的实例被命名,则该端口将始终是动态的.1433不知道在哪里看到的,是我弄错了.

So what I am guessing happens is that even though Tedious lets you include instance name in 'options' it either doesn't use it or can't use it as it needs to be used. After doing some research, what should be happening is when you give SQL Server the instance name, it redirects you from port 1433 to the dynamic port it is using for that instance. I didn't know it was using a dynamic port, but if your instance is named the port will always be dynamic. I don't know where I saw it broadcasting on 1433, that was my mistake.

要检查动态端口,请看这里:

To check the dynamic port, look here:

根据此信息,我将代码更改为:

From this information, I changed my code to this:

var config = {
  userName: 'username',
  password: 'password',
  server: 'XXXXX',

  options: {
    port: 49175,
    database: 'databasename',
    instancename: 'SQLEXPRESS'
  }
};

现在一切都很好,希望这对某人有所帮助.

All is good now, hope this helps someone.

这篇关于无法使用 Node.js 和 Tedious 连接到 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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