2017-07-15 5 views
1

npm mssqlモジュールを使用してmssqlサーバーに接続しようとしています。私は以下のエラーを受けています。私はそれを検索しようとしましたが、何人かのユーザーが既にそれを報告してくれただけで何の助けも得られませんでした。GitHub次のように接続を作成し、手順を実行するための私のコードがあるNPM MSSQL - エラー:uncaughtException:nullのプロパティ 'release'を読み取ることができません

error: uncaughtException: Cannot read property 'release' of null date=Sat Jul 15 2017 02:03:59 GMT+0000 (UTC), pid=10150, uid=1000, gid=1000, cwd=/home/ubuntu/server/gcap-server-exp, execPath=/usr/bin/nodejs, version=v6.11.1, argv=[/usr/bin/nodejs, /usr/lib/node_modules/pm2/lib/ProcessContainerFork.js], rss=70537216, heapTotal=47235072, heapUsed=35834656, external=18214141, loadavg=[0.14794921875, 0.10498046875, 0.02880859375], uptime=2206463 
TypeError: Cannot read property 'release' of null 
    at ConnectionPool.release (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/mssql/lib/base.js:199:14) 
    at Request.tds.Request.err [as userCallback] (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/mssql/lib/tedious.js:892:25) 
    at Request._this.callback (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/tedious/lib/request.js:47:27) 
    at Connection.message (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/tedious/lib/connection.js:1401:27) 
    at Connection.dispatchEvent (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/tedious/lib/connection.js:687:45) 
    at MessageIO.<anonymous> (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/tedious/lib/connection.js:602:18) 
    at emitNone (events.js:86:13) 
    at MessageIO.emit (events.js:185:7) 
    at ReadablePacketStream.<anonymous> (/home/ubuntu/server/gcap-server-exp/node_modules/atpl-models/node_modules/tedious/lib/message-io.js:102:16) 
    at emitOne (events.js:96:13) 

-

sql.close() 
sql.connect(sqlConfig).then(pool => { 
    return pool.request() 
    .input('input', sql.NVarChar, input_value) 
    .execute('someProcedure').then(result => { 
     result.recordsets.forEach(record => { 
     record.forEach(recordChild => { 
     // Do something about the recordChild ... 
     }) 
     }) 
    }, err => { 
     // Log err 
     console.log(err) 
    }).catch(err => { 
     // ... error checks 
     console.log(err) 
    }) 
}) 

上記sqlConfigパラメータがある -

sqlConfig = { 
    user: 'username', 
    password: '******', 
    server: 'xxx.xxx.xxx.xxx', 
    database: 'database', 
    pool: { 
    max: 10, 
    min: 0, 
    idleTimeoutMillis: 30000 
    } 
} 
+0

mssql接続を解放するときにこのエラーが発生しているようです... –

+0

はい、接続を解放する間にエラーが発生しますが、mssqlモジュールを使用すると接続を解放するマニュアラコードはありませんそれ自身。 – Jeet

+0

btwどこにあなたのコードで接続を解放していますか。 –

答えて

1

私はこれと同じ問題を抱えて、ここだました私はこのエラーを避けるために何をしなければならなかったのですか?ここで

async function connectToDb() { 
    const pool = await new sql.ConnectionPool(connectionConfig).connect(); 
    return pool; 
} 

がクエリを行う機能です:

は、ここでデータベースへの接続を取得する私の機能です

async function someDatabaseFunction(args, done) { 
    let pool; 
    let ps; 

    try { 
     pool = await connectToDb(); 
     ps = new sql.PreparedStatement(pool); 
     ps.input('input1', sql.VarChar(10)); 

     const sqlStr = 'my query goes here'; 

     await ps.prepare(sqlStr); 
     const result = await ps.execute({ groupId: args.groupId, status: args.status }); 

     done(null, result); 
    } catch (error) { 
     done(error); 
    } finally { 
     if (ps) await ps.unprepare(); 
     if (pool) pool.close(); 
    } 
} 
私にとっての問題は、finallyブロックに私が呼んでいたということでした

ps.unprepare()が機能しませんでしたが、awaitは機能しませんでした。私はpool.close()の機能に行きました。 awaitを入力してps.unprepare私のエラーを取り除いた。

あなたの状況に当てはまるかどうかは確かではありませんが、sql.connectの直前でsql.close()と呼ばれています。あなたがヌル値でsql.closeと呼んでいる可能性がありますが、その結果エラーです。

+0

はい、それはすべき方法です、私は最近、それを理解しました。答えに感謝します。 – Jeet

関連する問題