PostgreSQL Connection String with ODBC driver in C

2019-09-06 09:27发布

Lately I've been trying to connect a PostgreSQL 9.6 database on my C# project but I've been struggling setting up the connection string correctly due to "Keyword not supported:driver".

After having read tons of information, I downloaded the ODBC.NET, I registered PostgreSQL in ODBC Data Sources (32x), referenced the Microsoft.Data.Odbc.dll in my project's directory and managed to have a successful connection with my database in the Visual Studio's Ultimate 2013, but when it came to accessing the data something went wrong.

This is my connection string and a glimpse of my project:

Furthermore this is my data source information:

enter image description here

1条回答
太酷不给撩
2楼-- · 2019-09-06 10:01

If you want to use ODBC to connect to PostgreSQL database use OdbcConnection

You can then instantiate a connection using DSN as ODBC data source identifier.

OdbcConnection DbConnection = new OdbcConnection("DSN=PostgreSQL30");

as specified here

There are also other ways to connect to PostreSQL without using ODBC driver. You might want to look at Npgsql .net library or EntityFramework with Npgsql library. More info about usage can be found here

查看更多
登录 后发表回答