我尝试使用VB.NET / VS2010连接到Postgres 9.5数据库。我已经安装了4.5 .NET框架,该项目的目标是" .NET Framework 4"。我使用Npgsql-3.2.5.msi来安装NpgSQL.dll并引用了dll,但无法构建项目,或者看到intellisense中的任何NpgSQL对象。我曾尝试将NuGet用于当前版本,但是当我尝试安装它时它会出错。我用了
"Install-Package Npgsql -Version 3.2.5"
我做了一些研究,并且能够安装NuGet Legacy软件包
"Install-Package Npgsql.EntityFrameworkLegacy -Version 2.2.7"
但该项目仍然拒绝构建,我仍然无法访问Npgsql对象,至少在intellisense中。当我尝试构建时,我得到了 "无法加载文件或程序集' PostGreSQL Test.exe'或其中一个依赖项。此程序集由比当前加载的运行时更新的运行时构建,无法加载。"作为一个错误。
任何帮助使用Npgsql与Visual Studio 2010一起使用的帮助将不胜感激!或者至少让我知道它是否不可能。这将是一个只读连接。
这里是我开始的示例代码块:
Private Sub GetData()
Using conn = New Npgsql.NpgsqlConnection(connectionString)
conn.Open()
' Retrieve all rows
Using cmd = New Npgsql.NpgsqlCommand("SELECT some_field FROM data", conn)
Using reader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader.GetString(0))
End While
End Using 'reader
End Using 'cmd
End Using 'conn
End Sub