Reputation: 247
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
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.
Upvotes: 3
Views: 18085
Reputation: 1517
For Ex:
string connstring = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
"localhost", "5432", "postgres", "metin", "ATALAY");
Upvotes: 0
Reputation: 2494
You may try that:
Driver={PostgreSQL};Server=IP address;Port=5432;Database=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
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.
Regards
Upvotes: 4