سؤال

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

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!!!!!')
});

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top