无法从节点连接到SQL Server

我使用这些版本:

node v4.7.3 mssql v3.2.1 

我使用mssql模块来连接服务器, 这里的文档是用于mssql的。

SQL服务器运行在Windows上,我在Windows系统中运行以下命令来确认SQL服务器的状态:

 > netstat -ano | findstr 1433 TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING 1452 TCP 127.0.0.1:1433 127.0.0.1:50093 ESTABLISHED 1452 TCP 127.0.0.1:50093 127.0.0.1:1433 ESTABLISHED 3636 

然后我使用nc来testing服务器的端口:

 $ nc -z msserver 1433 Connection to msserver port 1433 [tcp/ms-sql-s] succeeded! 

这表明我可以连接端口。

但是,我无法通过以下configuration通过mssql模块连接服务器:

 { user: 'sa', password: 'pwd', server: 'msserver', port: '1433', database: 'dbname', pool: { max: 10, min: 0, idleTimeoutMillis: 30000, }, requestTimeout: 0, connectionTimeout: 15000, debug: true, } 

我使用debug: true来获取debugging信息,如下所示:

 connected to msserver:1433 Sent type:0x12(PRELOGIN), status:0x01(EOM), length:0x002F, spid:0x0000, packetId:0x01, window:0x00 PreLogin - version:0.0.0.1 1, encryption:0x02(NOT_SUP), instopt:0x00, threadId:0x00000000, mars:0x00(OFF) State change: Connecting -> SentPrelogin socket ended State change: SentPrelogin -> Final connection to msserver:1433 closed State is already Final 

我的代码在这里:

 mssql.connect(config.mssql).then(function() { console.log('connected'); new mssql.Request().query('select top 1 * from qmx.dbo.QMXStockPool order by ID desc', (err, records) => { console.log(err, records); }); }).catch(function(err) { console.log(err); }); 

没有输出,没有错误,很快就完成了。

从注释看来,这个错误logging在SQL Server的错误日志文件中:

无法连接,因为已达到“4”个用户连接的最大数量。

这意味着有人明确设置了最大并发连接限制。 默认是无限连接。

解决方法是将该值更改回默认值0 = unmlimited。 GUI方法是打开SSMS,转到服务器属性中的Connections选项卡,并将Maximum number of concurrent connections设置为0。 在这里输入图像说明

另一个选项,在连接到SQL Server时发生错误中描述- “无法连接,因为已经达到'1'用户连接的最大数量”。还有许多其他文章,是使用sqlcmd从命令行连接并更改configuration设置:

 sp_configure 'show advanced options', 1; go reconfigure go sp_configure 'user connections', 0 go reconfigure go