6

执行几个 SQL 语句后总是出现以下错误。

我在用

var sql = require("mssql");

(节点:12240)[DEP0064] DeprecationWarning:不推荐使用 tls.createSecurePair()。请改用 tls.Socket。警告.js:18(节点:12240)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:2):ConnectionError:无法连接到Server-100:15000毫秒内未定义警告.js:18(节点:12240)[DEP0018]弃用警告:未处理的承诺拒绝已被弃用。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。警告.js:18(节点:12240)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:4):ConnectionError:无法连接到Server-100:15000毫秒内未定义warning.js:18

ConnectionError: Failed to connect to server-100:undefined in 15000ms
 at Connection.tedious.once.err (d:\API\node_modules\mssql\lib\tedious.js:216:17)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at Connection.emit (events.js:210:7)
    at Connection.connectTimeout (d:\API\node_modules\tedious\lib\connection.js:634:12)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5)

以下是代码:

module.exports = function (data) {

    return new Promise(function (resolve, reject) {

        var database = new sql.ConnectionPool({
        user: 'sa',
        password: 'password',
        server: 'Server-100',
        database: 'SQLDB',
        options: {
            encrypt: true,
            useUTC: true
        },
        pool: {
            max: 10,
            min: 0,
            idleTimeoutMillis: 60000
        }
    });

        database.connect().then(function () {

            var req = new sql.Request(database);
            req.input(data.parameter.Name, data.parameter.DataType, data.parameter.Value);                
            req.execute(data.procedureName).then(function (result) {
                database.close();
                return resolve(result);
            }).catch(function (err) {
                database.close();
                return reject(err);
            });

        }).catch(function (err) {
            database.close();
            return reject(err);
        });
    });
}

发生异常:ConnectionError ConnectionError: 无法连接到 10.0.2.183:undefined in 15000ms at Connection.tedious.once.err (d:\Projects\node_modules\mssql\lib\tedious.js:216:17) at Object.onceWrapper (events.js:316:30) 在 emitOne (events.js:115:13) 在 Connection.emit (events.js:210:7) 在 Connection.connectTimeout (d:\Projects\node_modules\tedious\lib\connection .js:634:12) 在 ontimeout (timers.js:469:11) 在 tryOnTimeout (timers.js:304:5) 在 Timer.listOnTimeout (timers.js:264:5)

你能建议这里有什么问题吗?

4

1 回答 1

-2

在服务器位置使用本地主机并尝试。

var database = new sql.ConnectionPool({
        user: 'sa',
        password: 'password',
        port:"1433",
        server: 'localhost',    //if your connecting to localhost\instance make sure you have the service 'SQL Server Browser' running. 
        database: 'SQLDB',
        options: {
            encrypt: true,
            useUTC: true
        },
        pool: {
            max: 10,
            min: 0,
            idleTimeoutMillis: 60000
        }
    });
于 2018-01-11T11:54:33.167 回答