我无法使用节点MsSQL库https://www.npmjs.com/package/mssql成功完成到我的数据库的事务。一切似乎都在执行,但是,我没有收到数据到我的数据库。非常感谢任何帮助,谢谢!
# Create connection
config =
user: ''
password: ''
server: ''
database: ''
connection = new sql.Connection(config)
# Send to table
sendData = (a, b, dsHost, dsUsername, dsSessionname, dsMode, dsRemotelocation, dsSessionactivity, dsActivityduration) ->
transaction = new sql.Transaction(connection)
transaction.begin (err) ->
if err
console.log err
else
request = new sql.Request(transaction)
request.query "INSERT INTO dbo.sessionManager SET host=?, username=?, sessionname=?, mode=?, remotelocation=?, sessionactivity=?, activityduration=?", [dsHost, dsUsername, dsSessionname, dsMode, dsRemotelocation, dsSessionactivity, dsActivityduration], (err, recordset) ->
transaction.commit (err, recordset) ->
if err
throw err
sendData()可以调用一次或一千次,具体取决于具体情况。
答案 0 :(得分:0)
request = new sql.Request(transaction)
request.query "INSERT INTO dbo.sessionManager SET host=?, ...], (err, recordset) ->
// I think that your query is incorrect, e.g. by db constraints.
// So you need check err here.
transaction.commit (err, recordset) ->
if err
throw err