Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

node连接mssql出错请指教

$
0
0
const dbConfig = require('./config').dbConfig;
const sql = require('mssql');

sql.connect(dbConfig).then(function() {

    new sql.Request().query(`select * from T_Weibo_Uids`).then(function(recordset) {
        console.dir(recordset);
    }).catch(function(err) {
        // ... query error checks
        console.log('query出错');
        throw err;
    });
    
}).catch(function(err) {
    console.log('连接出错');
    // ... connect error checks
    throw err;
});

配置如下
dbConfig :{
        user: 'xxx',
        password: 'xxxx',
        server: 'xxxx',
        database: 'xxxx',
        pool: {
            max: 10,
            min: 0,
            idleTimeoutMillis: 30000
        }
    }

连接出错
(node:14762) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: "listener" argument must be a function
(node:14762) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


//这样写还是同样的错误,是不是哪里少了个参数,完全看不懂这个错误
sql.connect(dbConfig, function(err) {
    if(err) throw err;
    console.log('连接成功');
});
events.js:307
    throw new TypeError('"listener" argument must be a function');
    ^

TypeError: "listener" argument must be a function
    at Socket.once (events.js:307:11)
    at Socket.connect (net.js:943:10)
    at Connection.connectOnPort (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:429:19)
    at Connection.connect (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:402:21)
    at Connection.initialiseConnection (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:77:12)
    at Connection.enter (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:975:19)
    at Connection.transitionTo (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:508:33)
    at new Connection (/Users/xx/Desktop/work/weiboApi/node_modules/tedious/lib/connection.js:66:10)
    at Object.cfg_pool.create (/Users/xx/Desktop/work/weiboApi/node_modules/mssql/lib/tedious.js:375:19)
    at Pool._createResource (/Users/xx/Desktop/work/weiboApi/node_modules/generic-pool/lib/generic-pool.js:354:17)

Viewing all articles
Browse latest Browse all 14821

Trending Articles