gpt4 book ai didi

sql-server - 无法使用node js连接到mysql windows身份验证

转载 作者:太空宇宙 更新时间:2023-11-04 01:54:13 25 4
gpt4 key购买 nike

这是我的 Node.js 代码

app.get('/', function (req, res) {
var config = {
server: 'localhost\\SQLEXPRESS2008',
database: 'TestingDB'
};

// connect to your database
sql.connect(config, function (err) {

if (err) console.log(err);

// create Request object
var request = new sql.Request();

// query to the database and get the records
request.query('select * from userform', function (err, recordset) {

if (err) console.log(err)

// send records as a response
res.send(recordset);

console.log(recordset);
});
});

});

请建议我连接 sql,并在命令提示符中运行后出现此错误

服务器正在端口 8020 上运行

{ 错误:无法连接到本地主机:15000 毫秒内未定义

    at Connection.tedious.once.err (D:\Nodejs\UsersCreate\node_modules\mssql\lib\tedious.js:216:17)
at Object.onceWrapper (events.js:293:19)
at emitOne (events.js:96:13)
at Connection.emit (events.js:191:7)
at Connection.connectTimeout (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:795:12)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
code: 'ETIMEOUT',
originalError:
{ ConnectionError: Failed to connect to localhost:undefined in 15000ms
at ConnectionError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\errors.js:12:12)
at Connection.connectTimeout (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:795:28)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
message: 'Failed to connect to localhost:undefined in 15000ms',
code: 'ETIMEOUT' },
name: 'ConnectionError' }
{ ConnectionError: Connection is closed.
at Request._query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:1299:37)
at Request._query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\tedious.js:497:11)
at Request.query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:1242:12)
at D:\Nodejs\UsersCreate\app.js:118:17
at _poolCreate.then.catch.err (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:269:7) code: 'ECONNCLOSED', name: 'ConnectionError' }
undefined

最佳答案

这可能有帮助:

  1. 在Windows服务中启动“SQL SERVER BROWSER”服务(我已将其配置为自动启动)

  2. 允许 SQL Server Express 通过 TCP/IP 接受端口 1433 的远程连接:http://support.webecs.com/kb/a868/how-do-i-configure-sql-server-express-to-allow-remote-tcp-ip-connections-on-port-1433.aspx

最后重新启动“SQL Server”和“SQL Browser Agent”服务

关于sql-server - 无法使用node js连接到mysql windows身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48577470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com