RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state
See original GitHub issueExpected behaviour:
transaction.begin & loop DML excute error Can’t reuse “request”?
error log :
C:\workspace\AX5UI>node test_transaction.js
{ RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state
at Request.tds.Request.err [as userCallback] (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:629:19)
at Request.callback (C:\workspace\AX5UI\node_modules\tedious\lib\request.js:37:27)
at Connection.makeRequest (C:\workspace\AX5UI\node_modules\tedious\lib\connection.js:1671:15)
at Connection.execSql (C:\workspace\AX5UI\node_modules\tedious\lib\connection.js:1449:10)
at Immediate.parent.acquire [as _onImmediate] (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:856:65)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
code: 'EINVALIDSTATE',
number: 'EINVALIDSTATE',
state: undefined,
originalError:
{ RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state
at RequestError (C:\workspace\AX5UI\node_modules\tedious\lib\errors.js:32:12)
at Connection.makeRequest (C:\workspace\AX5UI\node_modules\tedious\lib\connection.js:1671:24)
at Connection.execSql (C:\workspace\AX5UI\node_modules\tedious\lib\connection.js:1449:10)
at Immediate.parent.acquire [as _onImmediate] (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:856:65)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
message:
'Requests can only be made in the LoggedIn state, not the SentClientRequest state',
code: 'EINVALIDSTATE' },
name: 'RequestError',
precedingErrors: [] }
{ TransactionError: Can't acquire connection for the request. There is another request in progress.
at Transaction.acquire (C:\workspace\AX5UI\node_modules\mssql\lib\base.js:813:30)
at Immediate._query.err (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:601:19)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5) code: 'EREQINPROG', name: 'TransactionError' }
{ TransactionError: Can't acquire connection for the request. There is another request in progress.
at Transaction.acquire (C:\workspace\AX5UI\node_modules\mssql\lib\base.js:813:30)
at Immediate._query.err (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:601:19)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5) code: 'EREQINPROG', name: 'TransactionError' }
C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:375
this._acquiredConnection.rollbackTransaction(err => {
^
TypeError: Cannot read property 'rollbackTransaction' of null
at Immediate._rollback.err (C:\workspace\AX5UI\node_modules\mssql\lib\tedious.js:375:32)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
C:\workspace\AX5UI>
Actual behaviour:
> test_db_insert()
>
> function test_db_insert(){
> const pool = new sql.ConnectionPool(config)
> pool.connect(err => {
> if(err) console.log(err)
> const transaction = new sql.Transaction(pool);
> const request = new sql.Request(transaction);
>
> transaction.begin(err => {
> if(err) return console.log(err);
>
> const array = [1, 2, 3];
>
> for(let TEST_ID of array){
> let db_insert = 'INSERT INTO T_TEST_TABLE VALUES(' + TEST_ID + ');'
> request.query(db_insert, (err, result) => {
> if(err){
> console.log(err)
> transaction.rollback()
> }
> })
> }
> transaction.commit()
> })
> })
> }
Configuration:
Windows 10 Pro X64
CREATE TABLE TEST_DB.dbo.T_TEST_TABLE (
TEST_ID int NOT NULL,
PRIMARY KEY (TEST_ID)
) GO
Software versions
- NodeJS : v10.16.0
- node-mssql : 5.1.0
- SQL Server: Microsoft SQL Server 2008 R2 (SP3)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Requests can only be made in the LoggedIn state ... - GitHub
The error Requests can only be made in the LoggedIn state, not the SentClientRequest state can be caused by a variety of different...
Read more >Requests can only be made in the LoggedIn state, not the ...
A few issues: 1) var Request = require('tedious').Request; seems to be missing; 2) the insert statement specifies six columns, but only five ...
Read more >Requests can only be made in the LoggedIn state, not the ...
Requests can only be made in the LoggedIn state, not the SentClientRequest state (code: 'EINVALIDSTATE')
Read more >Requests can only be made in the LoggedIn state, not the ...
[Solved]-Requests can only be made in the LoggedIn state, not the SentClientRequest state-node.js ... The solution is using from one query request and....
Read more >node mssql insert - You.com | The AI Search Engine You Control
'Requests can only be made in the LoggedIn state, not the SentClientRequest state'. I assume I'm setting up the bulk insert as part...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you’ll be needing a request per item in your array. You’re running multiple queries on the same request before waiting for the previous one to finish:
Closing as not a defect with the library.
willmorgan!! Thank you so much!
Using “async.eachSeries” instead of “for” statements makes it synchronous and works well.
You are my benefactor best regards!!
Here is the code changed as follows.