Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions

You are not logged in.

Announcement

#1 2014-12-03 09:54:55

hoppelsche
Member
Registered: 2014-12-03
Posts: 1

Node.js connect with Microsoft Server SQL

Hi all,

first of all thank you for your help.

I want to connect my node.js webserver with a microsoft server sql. I allready installed npm install mssq and tedious. I created the minimal.js - File:

var Connection = require('tedious').Connection;
var Request = require('tedious').Request;

var config = {
  server: 'example',
  userName: 'exa',
  password: 'mple'
  /*
  ,options: {
    debug: {
      packet: true,
      data: true,
      payload: true,
      token: false,
      log: true
    },
    database: 'example',
    encrypt: true // for Azure users
  }
  */
};

var connection = new Connection(config);

connection.on('connect', function(err) {
    // If no error, then good to go...
    executeStatement();
  }
);

connection.on('debug', function(text) {
    //console.log(text);
  }
);

function executeStatement() {
  request = new Request("select 42, 'hello world'", function(err, rowCount) {
    if (err) {
      console.log(err);
    } else {
      console.log(rowCount + ' rows');
    }

    connection.close();
  });

  request.on('row', function(columns) {
    columns.forEach(function(column) {
      if (column.value === null) {
        console.log('NULL');
      } else {
        console.log(column.value);
      }
    });
  });

  request.on('done', function(rowCount, more) {
    console.log(rowCount + ' rows returned');
  });

  // In SQL Server 2000 you may need: connection.execSqlBatch(request);
  connection.execSql(request);
}

No i typed in terminal following:

node minimal.js and i get following error:

{ [RequestError: Requests can only be made in the LoggedIn state, not the Connecting state]
  name: 'RequestError',
  message: 'Requests can only be made in the LoggedIn state, not the Connecting state',
  code: 'EINVALIDSTATE' }


What I'm doing wrong?

Offline

#2 2014-12-03 10:40:24

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Node.js connect with Microsoft Server SQL

How does LHC is related to things you are doing?

Offline

Board footer