Question

I'm trying to connect to a database on Azure using node-mssql. My development system is Windows 7 and I have had no success at all getting node-sqlserver to install via WebMatrix.

My question is two part: Firstly is there any reason that even when I follow the instructions from Microsoft that I get errors with node-sqlserver? Trying the naive approach using NPM inside WebMatrix I get the following error:

An error occurred.

"C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "node-sqlserver" "--json"


Exit status 1

Failed at the node-sqlserver@0.1.0 install script.
This is most likely a problem with the node-sqlserver package,
not with npm itself.
Tell the author that this fails on your system:
    node-gyp rebuild
You can get their info via:
    npm owner ls node-sqlserver
There is likely additional logging output above.



Failed: npm reported an error.

NodeNpm.NpmException: Failed: npm reported an error.
   at NodeNpm.NpmApi.Install(INpmPackage package)
   at Microsoft.WebMatrix.NpmGallery.CachingPackageManger.InstallPackage(INpmPackage package)
   at Microsoft.WebMatrix.NpmGallery.PackageViewModel.Install()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

The machine has VS2012 Professional installed.

The second part of my question is, is there any reason why using node-mssql won't work under Azure? I simply get a failed connection error, even though I've verified the details several times (substituted placeholders for actual values below):

var config = {
  user: '{username}',
  password: '{password}',
  server: 'tcp:{server}.database.windows.net',
  database: '{database}'
}

I get the following error:

{"name":"ConnectionError","message":"connection to tcp:{server}.database.windows.net:1433 >- failed Error: getaddrinfo ENOTFOUND"}

I realise that node-sqlserver is the best way to do it under Azure but I've tried for a couple of days with no success. Is there anything obvious I am missing?

Was it helpful?

Solution

1) You can solve it by downloading precompiled node-sqlserver driver from this repo. I was not able to compile sources on my machine even with all dev dependencies installed as well.

2) node-mssql module use three different drivers to communicate with sql server. Your config doesn't specify any driver, so the default one is used - Tedious. You must change your config to make it work correctly:

var config = {
    user: '{username}',
    password: '{password}',
    server: '{server}.database.windows.net', // simply remove "tcp:"
    database: '{database}'
}

There is also an option to use node-mssql with node-sqlserver but to make it work, you have to install compiled node-sqlserver driver manually. Config should look like this:

var config = {
    driver: 'msnodesql',
    user: '{username}',
    password: '{password}',
    server: 'tcp:{server}.database.windows.net',
    database: '{database}'
}

OTHER TIPS

I was using SQL Azure from Node.js last year when the module was named node-sqlserver so my answer might not work.

Ref your first problem, node-mssql should need to be compiled through node-gyp and C++ during NPM installation. So you'd better check if you have C++ compiler installed. When I was installing it told me I need VS2010 C++. Not sure if you need it now, or any later version. You can run npm install node-mssql from command window and you should get a log file if it failed, should be npm-error.log or something similar.

Ref your second problem, when I was using this module I use connection string. Could you double check your username was specified in format user@server. Also double check if your SQL Azure firewall was opened for other cloud services.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top