简体   繁体   中英

Database connection failed SQL Server 2012 Express + node.js

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?

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";

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM