c#连postgresql出现不支持关键字: “provider”错误

c#连接postgresql 数据库,照着例子使用 SqlConnection 结果报出异常,System.ArgumentException:“不支持关键字: “provider”。”

SqlConnection Connection = new SqlConnection( GetConnectionString())

原来为了连接postgresql用的是OleDb连接,而SqlConnection 是专门用于SQL Server 的,所以出错。看来用c#的时候还是微软自己的全家桶比较方便。

使用 Sql 开头的对象,名称空间是:
System.Data.SqlClient

使用 OleDb 开头的对象,名称空间是:
System.Data.OleDb

ref: https://blog.csdn.net/l8487/article/details/2170843