如何将SQL数据库与节点连接 [英] how to connect a SQL database with node
本文介绍了如何将SQL数据库与节点连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想连接一个sql db和node,我找到这个npm包
https:// www.npmjs.com/package/mssql [ ^ ]
和我开始但我没有做到
i want to connect a sql db with node and i find this npm package
https://www.npmjs.com/package/mssql[^]
and i started but i didn't make to
var sql = require('mssql');
var config = {
user: '',
password: '',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: 'dbUsers'
}
sql.connect(config, function(err) {
// error check
throw err; // not sure about this
var request = new sql.Request();
request.query('select * from tblUsers'); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
console.log(columns);
});
request.on('row', function(row) {
console.log (row);
});
});
推荐答案
为了安全起见,您可以测试连接参数吗?确保他们是正确的?我在互联网上找到了这个开源项目: DbAccess Tester [ ^ ]。
其次,请确保在Sql Server中启用了混合模式身份验证。并且用户还具有登录权限。本文包括: http://kb.kcsi.ca/Knowledgebase/How-to-Change-from-Sql-Server-Windows-mode-to-Mixed-Mode-SQL-SERVER-2008 [ ^ ]
*注意:您无需更改密码。此外,用户不必是sa。
最后通过右键单击服务器名称并单击重新启动重新启动管理工作室。稍等片刻,服务重新开始,然后继续。
如果这没有用,请告诉我。然后我们可以进一步诊断。
Just to be on the safe side, can you test the connection parameters to make sure they're correct? I found this open source project on the internet: DbAccess Tester[^].
Second, make sure "Mixed mode" authentication is enabled in Sql Server. And also that the user has login permission. This article covers both: http://kb.kcsi.ca/Knowledgebase/How-to-Change-from-Sql-Server-Windows-mode-to-Mixed-Mode-SQL-SERVER-2008[^]
*Note: You do not need to change the password. Also, the user doesn't have to be sa.
Finally restart management studio by right clicking the server name and clicking "Restart". Wait a few moments for the service to restart before proceeding.
Let me know if this doesn't help. We can then diagnose further.
这篇关于如何将SQL数据库与节点连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文