0
votes

I've created a MySQL RDS on AWS console. Then I successfully connected to that RDS in MySQL Workbench using following steps:

  1. Connection Method: Standard (TCP/IP)
  2. Hostname: zargham.ccir1327bjhl.us-east-2.rds.amazonaws.com
  3. Port: 3306
  4. Username: [given at the time of RDS creation]
  5. Password: [given at the time of RDS creation]

Then I try to connect it in my Asp.net core application, and it is giving me error on 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];"

Although OpenConnection() successful when I connect to localhost on same port.

Exception ImageIn-bound access AWS ImageOut-bound access AWS Image

1

1 Answers

1
votes

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