我需要为模块提供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上发现了类似的问题,问题是“禁用的TCP/IP”。我检查了此端口,并使用此端口1443启用了它。

最佳答案

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

的情况下



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

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

如果数据库处于联机状态,则下一步是检查用户是否可以访问数据库(如果它已映射到数据库:)
 select *
 from yourDB.sys.database_principals
 where name = 'YourUserName';

此代码仅对检查与sql服务器登录名相对应的用户是否存在有效(Windows登录名可以使用Windows组登录名访问服务器,用户也是如此)

万一该用户不存在,我们应该为此登录名创建用户并给他适当的权限。这是用户保护的链接
CREATE USER (Transact-SQL)

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

10-10 00:10
查看更多