简体   繁体   English

无法将 Azure 上的 Web 应用程序连接到远程数据库

[英]Unable to connect Web App on Azure to remote database

I deployed a next js web application on to Azure Web App Service , and want to use it to connect to existing remote database, however I am keep getting such error in the log stream: I deployed a next js web application on to Azure Web App Service , and want to use it to connect to existing remote database, however I am keep getting such error in the log stream:

2021-04-23T18:09:17.315942065Z Error: connect ECONNREFUSED 127.0.0.1:3306
2021-04-23T18:09:17.315993564Z     at Query._callback (/home/site/wwwroot/.next/server/pages/api/getFromUrl.js:128:16)
2021-04-23T18:09:17.316000664Z     at Query.Sequence.end (/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
2021-04-23T18:09:17.316013164Z     at /node_modules/mysql/lib/Pool.js:205:13
2021-04-23T18:09:17.316017064Z     at Handshake.onConnect (/node_modules/mysql/lib/Pool.js:58:9)
2021-04-23T18:09:17.316020764Z     at Handshake.<anonymous> (/node_modules/mysql/lib/Connection.js:526:10)
2021-04-23T18:09:17.316025064Z     at Handshake._callback (/node_modules/mysql/lib/Connection.js:488:16)
2021-04-23T18:09:17.316028764Z     at Handshake.Sequence.end (/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
2021-04-23T18:09:17.316032364Z     at Protocol.handleNetworkError (/node_modules/mysql/lib/protocol/Protocol.js:369:14)
2021-04-23T18:09:17.316035964Z     at PoolConnection.Connection._handleNetworkError (/node_modules/mysql/lib/Connection.js:418:18)
2021-04-23T18:09:17.316039564Z     at Socket.emit (events.js:315:20)

My db connection in the app is:我在应用程序中的数据库连接是:

export const db = mysql.createPool({
    host: 'abcd.efghosting.com',
    port: 3306,
    database: 'pwpush',
    user: 'pwpush_user',
    password: ....,
    multipleStatements: true,
});

Not sure why it's trying to connect to 127.0.0.1:3306不知道为什么它试图连接到127.0.0.1:3306

I tried to open something like hybrid-connection to the database endpoint but that didn't work.我试图打开与数据库端点的混合连接之类的东西,但这没有用。

Troubleshooting故障排除

  1. Check which db.js you use.检查您使用的是哪个db.js

  2. Use hybrid-connection correctly.正确使用混合连接。

Create a new Hybrid Connection and set the Endpoint Host name with the actual name/IP address, where the Hybrid Connection Manager is installed.创建一个新的混合连接并将端点主机名设置为安装混合连接管理器的实际名称/IP 地址。

For more details, please refer Tassisto's answer.有关详细信息,请参阅 Tassisto 的回答。

Web API hosted on Azure doesn't return On-Premise Data after Get Request 托管在 Azure 上的 Web API 在获取请求后不返回本地数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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