使用 ODBC 驱动程序连接 postgresql 的连接字符串是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11343628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:04:03  来源:igfitidea点击:

What is the connectionstring to connect with postgresql using ODBC driver?

postgresql

提问by Ranjan Panigrahi

I am currently working with a task to connect with PostgreSQL and retrieve data from that DB to my .net application,I am using the code like

我目前正在处理与 PostgreSQL 连接并将数据从该数据库检索到我的 .net 应用程序的任务,我使用的代码如下

OdbcConnection con = new OdbcConnection("Driver={PostgreSQL };Server=localhost;Port=2012;Database=DataCenter;Uid=postgres;Pwd=post@123;");

but it is throwing an ODBException. Please suggest me a code.

但它正在抛出一个ODBException. 请给我建议一个代码。

回答by Bgi

You may try that:

你可以试试:

Driver={PostgreSQL};Server=IP address;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

驱动程序={PostgreSQL};服务器=IP 地址;端口=5432;数据库=myDataBase;Uid=myUsername;Pwd=myPassword;

You can definitely find more information on this website: http://www.connectionstrings.com/And in your case particularely on this page: http://www.connectionstrings.com/postgre-sql#p51

您绝对可以在此网站上找到更多信息:http: //www.connectionstrings.com/在您的情况下,尤其是在此页面上:http: //www.connectionstrings.com/postgre-sql#p51

If it does not solve your problem it is that the problem doesn't come from the connection string but your configuration of PostgreSQL. You might want to check that you're able to connect to the server using "psql" (for example) from your client computer.

如果它不能解决您的问题,则问题不是来自连接字符串,而是您的 PostgreSQL 配置。您可能想要检查您是否能够使用“psql”(例如)从您的客户端计算机连接到服务器。

Regards

问候

回答by Metin Atalay

For Ex:

例如:

 string connstring = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
                           "localhost", "5432", "postgres", "metin", "ATALAY");