PostgreSQL的适当连接语法是什么



我有一个C#应用程序当前正在运行,其中sqlserver作为数据库。我使用 Dapper 的连接语句如下:

using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
connectionString="Server=127.0.0.1;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"

我正在尝试为 postgresql 获取与上述类似的连接字符串,也使用 Dapper

我已经尝试了下面的 2 个语句,我认为它们相当于上面的 sqlserver 行

using (IDbConnection connection = new System.Data.OleDb.OleDbConnection(GlobalConfig.CnnString(db)))
connectionString="Server=(localhost:5432);Database=Tournaments;Integrated Security=true;" providerName="Npgsql"/>

系统只是没有响应。我可能做错了什么?

只需尝试以下连接字符串。您可以使用本地主机或 127.0.0.1

connectionString="Host=127.0.0.1;Port=5432;Database=Tournaments;Integrated Security=true;" providerName="Npgsql"/>

最新更新