PostgreSQL的ODBC 64位驱动程序结果为QUOT;结构错配QUOT;驱动程序、结构、结果、ODBC

2023-09-09 21:17:07 作者:啥是社会儿?

我正在运行Win 7的64,最新的PostgreSQL 64位,我安装了64位ODBC驱动程序(0310-64)。使用两个ODBC控制面板,我可以创建一个32位和64位的连接。这两种测试OK。

I am running Win 7 64, the latest PostgreSQL 64 bit, and I installed the 64 bit ODBC driver (0310-64). Using the two ODBC control panels, I can create both a 32 and a 64 bit connection. Both test ok.

在VS 2010例preSS,我安装了MS的ODBC驱动程序1.0.4030.0。我可以连接到32位DSN,但是64位的人给的架构不匹配错误。

In VS 2010 Express, I installed MS's ODBC driver 1.0.4030.0. I can connect to the 32 bit DSN, but the 64 bit one gives the the architecture mismatch error.

这是没有意义的,因为我设置的是64位DSN 64位ODBC控制面板,在这里我得到了64位PG作为一个选项(不像32位CP)上。我选择了UNI code版本。

This doesn't make sense because I set up the 64 bit DSN on the 64 bit ODBC control panel, where I was given 64 bit PG as an option (unlike on the 32 bit CP). I selected the UNICODE version.

推荐答案

要使其与64位DSN和Visual C#2010例preSS版编辑的项目设置工作文件的.csproj(如WindowsFormsApplication1.csproj),并设置< STRONG> PlatformTarget 属性为 64

To make it work with 64 bit DSN and Visual C# 2010 Express Edition edit project settings file .csproj (e.g. WindowsFormsApplication1.csproj) and set PlatformTarget property to x64:

<PlatformTarget>x64</PlatformTarget>

Futhermore你不需要安装Microsoft ODBC .NET数据提供程序的驱动程序外,因为它包含在.NET作为的 System.Data.Odbc 的命名空间。

Futhermore you don't need to install Microsoft ODBC .NET Data Provider driver externally, because it's included in .NET as System.Data.Odbc namespace.

例如:

private void button1_Click(object sender, EventArgs e)
{
    OdbcConnection cn = new OdbcConnection("dsn=PostgreSQL35W");
    OdbcCommand cmd = new OdbcCommand("SELECT version()", cn);
    cn.Open();

    richTextBox1.AppendText(cmd.ExecuteScalar().ToString());

    cn.Close();
}

结果:

也可以考虑使用 Npgsql 代替。这似乎是pretty的共同PostgreSQL的接口,用于.NET。

Also consider use of Npgsql instead. It seems to be pretty common PostgreSQL interface for .NET.