I was trying to deploy an application in AWS elastic beanstalk with connection string inside web.config file everything works fine. But when I tried to implement by setting environment variables in AWS application it did not work. What I did was I added AWS tags key value pair in aws like RDS_DATABASENAME
- admin then i added those in web.config like
<add key="RDS_DB_NAME" value="RDS_DB_NAME"/>
<add key="RDS_USERNAME" value="RDS_USERNAME"/>
<add key="RDS_PASSWORD" value="RDS_PASSWORD"/>
<add key="RDS_HOSTNAME" value="RDS_HOSTNAME"/>
<add key="RDS_PORT" value="*RDS_PORT" />
Then while building connectionString I used this:
var appConfig = ConfigurationManager.AppSettings; // trying to get connection details from enviornment varibales
string dbname = appConfig["RDS_DB_NAME"];
if (string.IsNullOrEmpty(dbname)) return null;
string username = appConfig["RDS_USERNAME"];
string password = appConfig["RDS_PASSWORD"];
string hostname = appConfig["RDS_HOSTNAME"];
string port = appConfig["RDS_PORT"];
SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
{
DataSource = hostname + "," + port,
InitialCatalog = dbname,
UserID = username,
Password = password
};
return sqlString.ToString();
I followed the aws doc itself somehow I missed something!