Skip to main content

Posts

Showing posts from January, 2018

Node.js - Querying from MS SqlServer and loading into DynamoDB

This is a script made with a collation of internet examples. The goal here is to load a DynamoDB table with records from a SQLServer table. For this example I'm using a local installation of DynamoDB. var Connection = require ( ' tedious ' ) . Connection ; var Request = require ( ' tedious ' ) . Request ; var TYPES = require ( ' tedious ' ) . TYPES ; var fs = require ( ' fs ' ) ; var AWS = require ( " aws-sdk " ) ; console . time ( " dbsave " ) ; // SQL Server configuration var config = { userName : ' username ' , password : ' password ' , server : ' serverIP ' , options : { //instanceName: 'MSSQLSERVER', -- didnt have to use this option port : 1433 , database : ' dbname ' } } // DynamoDB configuration AWS . config . update ( { region : " us-west-2 " , en...

NodeJS MSSQL connection error "EINVALIDSTATE"

It took me some time to find the reasons for the connection error below: Requests can only be made in the LoggedIn state, n…", code: "EINVALIDSTATE" I was trying to connect to MS Sql server using Node JS TEDIOUS package. The code from the Microsoft  is very simple and didn't return a more complete error message. This is the original code: ... var connection = new Connection(config);  connection.on( 'connect' , function ( err ) {  // If no error, then good to proceed.  console .log( "Connected" );  executeStatement(); }); ... Checking the internet a bit more, I found a way to get more insight into the error: ... var  connection =  new  Connection(config);  connection.on( 'connect' ,  function ( err )  {  if (err) return console.error(err);   console .log( "Connected" );  executeStatement(); }); ... That raised: ConnectionError {message: "Failed to connect to 10.0.0.100:1433 - c...