I have an ASP.NET app, and to build a connection string from DATABASE_URL variable I used a following code:
var connUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
// Parse connection URL to connection string for Npgsql
connUrl = connUrl.Replace("postgres://", string.Empty);
var pgUserPass = connUrl.Split("@")[0];
var pgHostPortDb = connUrl.Split("@")[1];
var pgHostPort = pgHostPortDb.Split("/")[0];
var pgDb = pgHostPortDb.Split("/")[1].Split("?")[0];
var pgUser = pgUserPass.Split(":")[0];
var pgPass = pgUserPass.Split(":")[1];
var pgHost = pgHostPort.Split(":")[0];
var pgPort = pgHostPort.Split(":")[1];
connString = $"Server={pgHost};Port={pgPort};Username={pgUser};Password={pgPass};Database={pgDb};";
so it looks like something like this: “Server=app-name-db.flycast;Port=5432;Username=my-username;Password=my-password;Database=db-name;”, However when i run my application, and need to fetch data from database, there is an error in browser console
GET 500 (Internal Server Error)
After looking through logs in dashboard i found some errors:
2023-11-07T14:44:03.478 app[918571e9b30d48] waw [info] fail: api.Program[0]
2023-11-07T14:44:03.478 app[918571e9b30d48] waw [info] An error occured during migration.
2023-11-07T14:44:03.478 app[918571e9b30d48] waw [info] Npgsql.NpgsqlException (0x80004005): Exception while performing SSL handshake
2023-11-07T14:44:03.478 app[918571e9b30d48] waw [info] ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
2023-11-07T14:44:06.167 app[918571e9b30d48] waw [info] fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
2023-11-07T14:44:06.167 app[918571e9b30d48] waw [info] An error occurred using the connection to database 'db-name' on server ''.
2023-11-07T14:44:06.178 app[918571e9b30d48] waw [info] fail: Microsoft.EntityFrameworkCore.Query[10100]
2023-11-07T14:44:06.178 app[918571e9b30d48] waw [info] An exception occurred while iterating over the results of a query for context type 'api.Data.DataContext'.
2023-11-07T14:44:06.178 app[918571e9b30d48] waw [info] System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
If I use fly postgres connect -a <postgres-app-name>
it works fine.
So what could be the issue?