PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Connessione al database Heroku Postgres con Asp.Net

Lo uso per "tradurre" DATABASE_URL in una stringa di connessione

var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
var databaseUri = new Uri(databaseUrl);
var userInfo = databaseUri.UserInfo.Split(':');

var builder = new NpgsqlConnectionStringBuilder
{
    Host = databaseUri.Host,
    Port = databaseUri.Port,
    Username = userInfo[0],
    Password = userInfo[1],
    Database = databaseUri.LocalPath.TrimStart('/')
};

return builder.ToString();