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

查看:460
本文介绍了无法使用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天全站免登陆