0

I'm getting the "Database connection failed" trying with the Node.JS driver for SQL and the example from: http://blogs.msdn.com/b/sqlphp/archive/2012/06/08/introducing-the-microsoft-driver-for-node-js-for-sql-server.aspx

The string I use against SQL Server Express 11.0 64-bit, local

var conn_str = "Driver={SQL Server Native Client 11.0};Server=(local);Database=MyDB;Trusted_Connection={Yes}"; 

I also tried "sa" and another local user vs Windows Authentication -- all without luck.

Running node 0.6.10 (the version supported by the SQL driver), SQL Server Config showing SQL Native Client 11, so the versions match.

Are there any ways to troubleshoot?? Any guides / tutorials where the connection was successful for my stack?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
NikG
  • 195
  • 1
  • 2
  • 10

2 Answers2

2

RESOLVED:

I had been trying to incorrectly access the named instance of SQL Express. Should be .\\SQLEXPRESS, not (local) or .\SQLEXPRESS.

The correct String:

 var conn_str = "Driver={SQL Server Native Client 11.0};Server=.\\SQLEXPRESS;Database=NPv1;Trusted_Connection=Yes";
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
NikG
  • 195
  • 1
  • 2
  • 10
0

Trusted connection tells the connection to use the Windows ID of the process. If you are hosting this in IIS, this id will be the one the application pool is using. Make sure this id has access to both the database server and the database. Using sa and other local users won't fix the problem unless you tell it to not use a trusted connection and then specify the user id and password in the connection string (btw, this approach is not recommended; stick with the trusted connection if you can).

Jeff Siver
  • 7,434
  • 30
  • 32
  • Thanks for the suggestion. I am using Node.js and running command line – NikG Jul 03 '12 at 15:25
  • Sorry, missed that part. You can still use trusted connection; change the windows user hosting the command line prompt. Or, better yet, use Powershell and start it with specific credentials. – Jeff Siver Jul 03 '12 at 16:15
  • What do you mean by "change the windows user" -- as in my user is administrator, what's the issue w/ the command line prompt being run by my user? – NikG Jul 03 '12 at 23:05
  • If you are running as local admin, there is no issue as long as you haven't changed the default permissions for SQL Server. But for deployment, you shouldn't really give the user hosting the site admin privileges. – Jeff Siver Jul 04 '12 at 17:39