javascript 无法使用 Node.js 和 Tedious 连接到 SQL Server
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32315817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot connect to SQL Server with Node.js and Tedious
提问by loganhuskins
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.
根据配置管理器,我已经检查并启用了 TCP/IP 并在端口 1443 上进行广播。SQL Server Browser 服务也在运行,如果没有,我读到可能会导致此类问题。我已经禁用了我的防病毒软件和防火墙,但这也没有帮助。
Any insight?
任何见解?
回答by loganhuskins
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 允许您在“选项”中包含实例名称,它要么不使用它,要么不能使用它,因为它需要使用。在做了一些研究之后,应该发生的事情是,当您为 SQL Server 提供实例名称时,它会将您从端口 1433 重定向到它用于该实例的动态端口。我不知道它使用的是动态端口,但是如果您的实例被命名,则该端口将始终是动态的。我不知道我在哪里看到它在 1433 上播放的,那是我的错误。
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.
现在一切都很好,希望这对某人有所帮助。
回答by no_stack_dub_sack
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 servicesas well. This and enabling TCP/IP and restarting the service were the keys for me.
此外,请务必同时启用 SQL Server Browser 服务。这和启用 TCP/IP 并重新启动服务是我的关键。
回答by MarceloRB
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'
}
回答by halfDigital
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:
并且您已检查以下所有内容:
- Enable TCP/IP
- Open Port 1433
- Config setup correctly (database, server, username and password}
- No Dynamic ports configured
- 启用 TCP/IP
- 打开端口 1433
- 配置设置正确(数据库、服务器、用户名和密码}
- 未配置动态端口
Check your SQL server version. In my case, I discovered that I could connect to SQL 2012, but not SQL server 2016with the same code. It appears SQL Server 2016 is not supported by the tedious driver yet.
检查您的 SQL 服务器版本。就我而言,我发现我可以使用相同的代码连接到 SQL 2012,但不能连接到SQL server 2016。看来乏味的驱动程序尚不支持 SQL Server 2016。