3

How can I connect to SQL Server or SQL Azure from node.js when running on Linux.

The drivers I found on npm all need Windows + VS2005. Is there anyway to access SQL Server from Linux?

2 Answers 2

2

The mssql package in nodejs can adapt to next drivers:

  • Tedious by Mike D Pilsbury (pure javascript - windows/osx/linux)
  • Microsoft Driver for Node.js for SQL Server by Microsoft Corporation (native - windows only)
  • node-tds by Chad Retz (pure javascript - windows/osx/linux)

It is stated that node-tds and Tedious both work on linux.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried it, but I can't manage to get a connection, do you have a working example?
2

I found a working solution, just using 'tedious' directly.

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

var config = {
    userName: 'myuser@servername',
    password: 'mypassword',
    server: 'servername.database.windows.net',

   // If you're on Windows Azure, you will need this:
   options: {
       encrypt: true
   }
};
var connection = new Connection(config);

connection.on('connect', function(err) {
    if(err)
        console.log(err)
    else
        console.log('works!!!!!')
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.