本文介绍了使用Asp.Net连接到Heroku Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找从外部应用程序连接到Heroku Postgres数据库的最佳方法。该应用程序位于asp.net中。我正在尝试使用NpgSQL,但收到证书未知错误。有人做过吗?您有任何指针吗?
I'm looking for the best way to connect to a Heroku Postgres database from an outside application. The application is in asp.net. I am trying to use NpgSQL but am getting a certificate unknown error. Has anyone done that? Do you have any pointers?
推荐答案
我用它来将DATABASE_URL转换为连接字符串
I use this to "translate" the DATABASE_URL to a connection string
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();
这篇关于使用Asp.Net连接到Heroku Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!