gpt4 book ai didi

sql-server - 具有 SQL Server (Microsoft) 数据库连接的 Node

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:16 24 4
gpt4 key购买 nike

我需要为模块提供 SQL 连接(使用名为 mssql 的库),因此我提供如下代码:

var config = {
server: "149.xxx.xx.x",
database: "Database",
user: "User",
password: "Password",
connectionTimeout: 300000,
requestTimeout: 300000,
pool: {
idleTimeoutMillis: 300000,
max: 100
}
};

function getEmp() {
var connection = new sql.Connection(config);
var req = new sql.Request(connection);

connection.connect(function (error) {
if(error) {
console.log(error);
return;
}
req.query('Procedure', function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
connection.close();
});
});
}

getEmp();`

我收到错误:

 { ConnectionError: Failed to connect to 149.xxx.xx.x:1433 - connect
ETIMEDOUT 149.xxx.xx.x:1433 at Connection.<anonymous>
(/Users/xx/Learning/NodeJS/srv-express/node_modules/mssql/lib/tedious.js:353:25)
at Connection.g (events.js:292:16) at emitOne (events.js:96:13) at
Connection.emit (events.js:188:7) at Connection.socketError
(/Users/xx/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:791:12)
at Socket.<anonymous>
(/Users/xx/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:33:15)
at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at
emitErrorNT (net.js:1277:8) at _combinedTickCallback
(internal/process/next_tick.js:80:11)


name: 'ConnectionError', message: 'Failed to connect to
49.xxx.xx.x:1433 - connect ETIMEDOUT 149.xxx.xx.x:1433', code: 'ESOCKET' }

确保数据正确 - DataGrip 此处连接正常。

我在google上发现了类似的问题,问题是Disabled TCP/IP。我检查了这个,它已通过此端口 1443 启用。

The TCP/IP, Named Pipes and Shared Memory is Enabled.

TCP Dynamic Ports: 1443 TCP Port: empty

最佳答案

要查找 18456 错误“用户登录失败...”的原因,应该检查 SQLServer 错误日志。

如果出现

Reason: Failed to open the explicitly specified database 'Database Name'

应该首先检查数据库的状态(如果它在线),如下所示:

 select name, 
user_access_desc,
state_desc
from sys.databases where name='yourDatabase'

如果数据库在线,下一步是检查用户是否可以访问数据库(如果它映射到数据库:)

 select * 
from yourDB.sys.database_principals
where name = 'YourUserName';

该代码仅适用于检查sql server登录对应的用户是否存在(windows登录可以使用windows组登录访问服务器,用户也可以)

如果用户不存在,我们应该为此登录创建用户并授予他适当的权限。这是用户创建的链接 CREATE USER (Transact-SQL)

关于sql-server - 具有 SQL Server (Microsoft) 数据库连接的 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45140669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com