0

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 [email protected] 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?

2 Answers 2

1

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}'
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Patrik, I was finally able to get it to compile thanks to this article blog.gluwer.com/2013/07/… so it now works.
0

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.

1 Comment

Hi Shaun, node-sqlserver is the Microsoft official driver, but I have had no success with it at all either on Azure or on IIS 7.5. node-mssql is a third party driver and it worked perfectly for me on IIS 7.5 under IISnode. I have tried installing node-sqlserver using both npm and by using the recommended method by Microsoft.

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.