question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RequestError: Requests can only be made in the LoggedIn state, not the Connecting state

See original GitHub issue

I see this error was talked about here: https://github.com/tediousjs/tedious/issues/458 and I tried the suggested solution, but it didn’t work for me.

Here is my code:

`

    exports.exec_sql_cmd = async function(cmd)

    {

    var config = {  

        server: 'xx.xx.xx.xx',

        authentication: {

            type: 'ntlm',

            options: {

                userName: 'master',

                password: 'masterp',

	   domain: 'the.domain.com'

            }

        },

        options: {            

            encrypt: false,

            database: 'tblTest'

        }

    };  

    var connection = new Connection(config);

    connection.on('connect', function(err) { 

        console.log("Connected");  

        executeStatement();

    });

 connection.connect();
      
function executeStatement() {  
    var request = new Request(cmd, function(err) {  
     if (err) {  
        console.log(err);}  
    });  
    
    request.on('row', function(columns) {  
        columns.forEach(function(column) {  
          if (column.value === null) {  
            console.log('NULL');  
          } else {  
            console.log("Row Inserted");  
          }  
        });  
    });
   
    request.on("requestCompleted", function (rowCount, more) {
        connection.close();
    });
    connection.execSql(request);  
}

}

`

I do get connected (this line runs: console.log(“Connected”); ), but then this error is thrown: RequestError: Requests can only be made in the LoggedIn state, not the Connecting state

The context of all this is: I’m trying to perform an INSERT from AWS Lambda back down to an On-Prem MS SQL database.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mShan0commented, Feb 2, 2022

I’m not 100% sure if this is the same issue you have, but there has been an issue with NTLM authentication when using Node 17 (as Tedious does not officially support Node 17 currently). If you throw the error inside of this block:

if (err) {
    console.log("CONNECTION ERROR: "+err);
    throw err;
}

and you see an error message similar to this one: https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported, Node 17 may be the issue since Node upgraded to OpenSSL v3 and there are some compatibility issues. If it is possible to downgrade to Node 16, try that.

If that does not fix your issue, can you enable debugging to see a more detailed log?

 var config = {  
        server: 'xx.xx.xx.xx',
        authentication: {
            type: 'ntlm',
            options: {
                userName: 'master',
                password: 'masterp',
	   domain: 'the.domain.com'
            }
        },
        options: {            
            encrypt: false,
            database: 'tblTest'
            // Add this to your configuration file. You can pick and choose which ones to enable. 
            debug: {
                packet: true,
                data: true,
                payload: true,
                token: true
            }
        }

    };  

Then add this event listener to output the debug messages:

  connection.on('debug', (msg) => {
    console.log(msg);
  });
0reactions
ANTGOMEZcommented, Feb 11, 2022

Sorry for the late response. But I did switch back to Node 16 and it worked.

Thank you for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requests can only be made in the LoggedIn state, not ...
In my example below, I'm trying to serially execute an array of functions. But the Requests can only be made in the LoggedIn...
Read more >
Requests can only be made in the LoggedIn state, not ...
Try checking and reporting connection errors, i.e.: connection.on("connect", function (err) { if(err) { console.log('Error: ', err) } else ...
Read more >
问答- 腾讯云开发者社区-腾讯云
sqlsql-servernode.jsrequestconnect ... Connected { RequestError: Requests can only be made in the LoggedIn state, not the Connecting state at RequestError ...
Read more >
Requests Can Only Be Made In The Loggedin State Not
I am starting a nodejs project and I need to connect my app to a sql server database.Using tedious I'm making the connection...
Read more >
[Solved]-Requests can only be made in the LoggedIn state ...
[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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found