PostgreSQL连接字符串,带有C#中的ODBC驱动程序,不支持关键字:驱动程序 [英] PostgreSQL Connection String with ODBC driver in C#, Keyword not supported: driver

查看:594
本文介绍了PostgreSQL连接字符串,带有C#中的ODBC驱动程序,不支持关键字:驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在尝试在我的C#项目上连接PostgreSQL 9.6数据库,但是由于关键字不支持:驱动程序",我一直在努力正确设置连接字符串.

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".

在阅读了大量信息之后,我下载了ODBC.NET,在ODBC数据源(32x)中注册了PostgreSQL,在项目目录中引用了Microsoft.Data.Odbc.dll,并设法与我的计算机成功建立了连接Visual Studio Ultimate 2013中的数据库,但是在访问数据时出了点问题.

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:

推荐答案

如果要使用ODBC连接到PostgreSQL数据库,请使用

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

然后您可以使用DSN作为ODBC数据源标识符来实例化连接.

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

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

此处

还有其他无需使用ODBC驱动程序即可连接到PostreSQL的方法.您可能需要查看 Npgsql .net库或带有Npgsql库的EntityFramework.可以在此处

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

这篇关于PostgreSQL连接字符串,带有C#中的ODBC驱动程序,不支持关键字:驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆