无法使用Node.js和Tedious连接到SQL Server

[英]Cannot connect to SQL Server with Node.js and Tedious


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

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

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

Here is my connection object:

这是我的连接对象:

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

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

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.

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

Any insight?

任何见解?

4 个解决方案

#1


15  

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.

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

To check the dynamic port, look here:

要检查动态端口,请在此处查看:

enter image description 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.

一切都很好,希望这有助于某人。

#2


1  

If you still got this error,

如果你仍然有这个错误,

"...'Failed to connect to Server:1433 - connect ECONNREFUSED Server IP:1433', code: 'ESOCKET' }"

“...'无法连接到服务器:1433 - 连接ECONNREFUSED服务器IP:1433',代码:'ESOCKET'}”

and you've checked all the following:

你检查了以下所有内容:

  1. Enable TCP/IP
  2. 启用TCP / IP
  3. Open Port 1433
  4. 打开端口1433
  5. Config setup correctly (database, server, username and password}
  6. 正确配置设置(数据库,服务器,用户名和密码}
  7. No Dynamic ports configured
  8. 没有配置动态端口

Check your SQL server version. In my case, I discovered that I could connect to SQL 2012, but not SQL server 2016 with the same code. It appears SQL Server 2016 is not supported by the tedious driver yet.

检查您的SQL Server版本。就我而言,我发现我可以使用相同的代码连接到SQL 2012,但不能连接到SQL Server 2016。似乎SQL Server 2016尚未被繁琐的驱动程序支持。

#3


1  

If anyone else is new to SQL Server like I am, and is dealing with this issue, once you enable TCP/IP in SQL Server Config Manager by following these steps:

如果其他人不熟悉SQL Server,并且正在处理此问题,请按照以下步骤在SQL Server配置管理器中启用TCP / IP:

> SQL Server Network Config

> SQL Server网络配置

> Protocols for YOURSQLSERVERINSTANCE

> YOURSQLSERVERINSTANCE的协议

> TCP/IP

> TCP / IP

> Enable

>启用

you get a warning message that looks like this:

你收到一条如下所示的警告信息:

Any changes made will be saved; however, they will not take effect until the service is stopped and restarted.

所做的任何更改都将被保存;但是,在服务停止并重新启动之前,它们不会生效。

I took this to mean, disconnect from the database service in SQL Server Management Studio and reconnect, but this needs to happen in SQL Server Config Manager under the SQL Server Services tab. Find you SQL Server instance, stop and restart it, and hopefully you will be golden! This worked like a charm for me. Oddly, enabling the Named Pipes protocol seemed to work without a restart (I could see the difference in the error message), so I thought for sure it had stopped and restarted as needed.

我这意味着,断开与SQL Server Management Studio中的数据库服务的连接并重新连接,但这需要在SQL Server服务选项卡下的SQL Server配置管理器中进行。找到你的SQL Server实例,停止并重启它,希望你会成为金色!这对我来说就像一个魅力。奇怪的是,启用命名管道协议似乎没有重启(我可以看到错误消息中的差异),所以我认为它已经停止并根据需要重新启动。

Also, be sure to enable SQL Server Browser services as well. This and enabling TCP/IP and restarting the service were the keys for me.

此外,还要确保启用SQL Server Browser服务。这个和启用TCP / IP并重新启动服务是我的关键。

#4


0  

If you still have problems after enabling TCP/IP protocol, I would suggest you check that SQL Server Browser Service is running. In my case I spent a lot of time till I realised it wasn't running.

如果启用TCP / IP协议后仍有问题,我建议您检查SQL Server Browser服务是否正在运行。在我的情况下,我花了很多时间,直到我意识到它没有运行。

This configuration run fine for me:

这个配置对我来说很好:

 var config = {
     user: 'user',
     password: 'userPwd',
     server: 'localhost',
     database: 'myDatabase',
     options: {
         truestedConnection: true,
         instanceName: 'SQLEXPRESS'
    }

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/08/31/d1083a19e4e08a283dac942ec5d28461.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号