[英]Can't connect to RDS in Asp.net core application
I've created a MySQL RDS on AWS console.我在 AWS 控制台上创建了一个 MySQL RDS。 Then I successfully connected to that RDS in MySQL Workbench using following steps:
然后我使用以下步骤成功连接到 MySQL Workbench 中的 RDS:
Then I try to connect it in my Asp.net core application, and it is giving me error on openConnection().然后我尝试在我的 Asp.net 核心应用程序中连接它,它在 openConnection() 上给我错误。 Following connection string is used:
使用以下连接字符串:
"Server=zargham.ccir1327bjhl.us-east-2.rds.amazonaws.com; Port=3306; Database=aws; Uid=[same as above]; Pwd=[correct Password];" “Server=zargham.ccir1327bjhl.us-east-2.rds.amazonaws.com;Port=3306;Database=aws;Uid=[同上];Pwd=[正确密码];”
Although OpenConnection() successful when I connect to localhost on same port.虽然当我连接到同一端口上的本地主机时 OpenConnection() 成功。
Try this method:试试这个方法:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
namespace MVP9App.Models
{
public class Helptest
{
public static string GetRDSConnectionString()
{
var appConfig = ConfigurationManager.AppSettings;
string dbname = appConfig["RDS_DB_NAME"];
if (string.IsNullOrEmpty(dbname)) return null;
string username = appConfig["<<RDSUSERNAME>>"];
string password = appConfig["<<RDSPASSWORD>>"];
string hostname = appConfig["<<RDSHOSTNAME>>"];
string port = appConfig["<<RDSPORT>>"];
return "Data Source=" + hostname + ";Initial Catalog=" + dbname + ";User ID=" + username + ";Password=" + password + ";";
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.