关系dbo.MyTable在模式和表确实存在时找不到 [英] Relation dbo.MyTable not found while schema and table do exist

查看:639
本文介绍了关系dbo.MyTable在模式和表确实存在时找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Mono 3.10 MVC 5.2应用程序中,我试图通过Entity Framework 6.1.1与PostgreSQL数据库建立连接。为此,我采取了以下步骤:


  1. 包含包 Npsql Npsql.EntityFramework 通过NuGet。

  2. 添加了< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.1.1 ,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> Web中的 configSections 元素。配置

  3. 添加< remove invariant =Npgsql>< / remove> < add name =Npgsqlinvariant =Npgsqldescription =。Postgresql Server的Ne​​t Framework数据提供者type =Npgsql.NpgsqlFactory,Npgsql,Version = 2.2.2,Culture = neutral / DbProviderFactories 元素 system.data Web.config

  4. 添加以下连接字符串< add name =ZkTestDatabaseConnectionconnectionString =Server = localhost; Port = 5432; Database = ZkTestDatabase; User Id = test; Password = password; CommandTimeout = 20;创建了一个名为 dbo 的实例框架

  5. >,名为 ZkTestDatabase 的数据库,名为 test 的用户,以及名为 dbo的表。作物到PostgreSQL中的此数据库(请参阅此脚本)。 li>

当我用用户 test 登录并执行 select * from dbo.Crops; (我也尝试通过创建一个表创建表dbo.Crops; 而不是创建表dbo.Crops; 。我得到正确的输出。



现在,当我去一个模型作物(根据这个映射到表格的约定作物)我收到消息:

  Npgsql.NpgsqlException 
错误:42P01:关系dbo.Crops不存在

描述:HTTP 500.Error处理请求。

详细说明:不eb例外。异常来源(应用程序或对象的名称):Npgsql。
异常堆栈跟踪:
在Npgsql.NpgsqlState +< ProcessBackendResponses> d__0.MoveNext()[$ 0x00000]
< filename unknown>:0在Npgsql.ForwardsOnlyDataReader.GetNextResponseObject
(Boolean cleanup)[0x00000] in< filename unknown>:0

我很高兴应用程序了解到它需要连接到数据库,并找到一个关系 dbo.Crops 。我有点伤心,但是无法找到关系。



*编辑:执行 select from pg_tables; 返回以下内容:

  schemaname | tablename | tableowner |表空间| hasindexes | hasrules | hastriggers 
-------------------- + ------------------------ - + ------------ + ------------ + ------------ + --------- - + -------------
public | dbo.Crops | zktest | | t | f | f

我不知道为什么会出现这个错误,我已经用尽了我有限的理解中的所有功能。我希望别人看到一个可能的解决方案。

解决方案

从pg_tables执行select *,看看是什么。那应该让你在正确的路上。


In our MVC 5.2 application on Mono 3.10 I am trying to set up a connection with a PostgreSQL database via Entity Framework 6.1.1. To do this I took the following steps:

  1. Included the packages Npsql and Npsql.EntityFramework via NuGet.
  2. Added the section <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.1.1, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> to the configSections element in Web.Config.
  3. Added <remove invariant="Npgsql"></remove> and <add name="Npgsql" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.2, Culture=neutral" /> to the DbProviderFactories element of system.data in the Web.config.
  4. Added the following connection string <add name="ZkTestDatabaseConnection" connectionString="Server=localhost;Port=5432;Database=ZkTestDatabase;User Id=test;Password=password;CommandTimeout=20;" providerName="Npgsql" /> that connects with Entity Framework context.
  5. Created a schema named dbo, a database named ZkTestDatabase, a user named test, and a table named dbo.Crops to this database in PostgreSQL (see this script).

When I am logged in with the user test and do select * from dbo.Crops; (I also tried making a table via create table "dbo.Crops"; instead of create table dbo.Crops;. I get the proper output.

Now, when I go a page with a model Crop (as per conventions this maps to a table Crops) I get the message:

Npgsql.NpgsqlException
ERROR: 42P01: relation "dbo.Crops" does not exist

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): Npgsql.
Exception stack trace:
at Npgsql.NpgsqlState+<ProcessBackendResponses>d__0.MoveNext () [0x00000] in 
<filename unknown>:0 at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject 
(Boolean cleanup) [0x00000] in <filename unknown>:0 

I am very happy that the application understands that it needs to connect to a database and find a relation dbo.Crops. I am a bit sad however that the relation cannot be found.

*Edit: while performing select * from pg_tables; the following is returned:

     schemaname     |        tablename        | tableowner | tablespace | hasindexes | hasrules | hastriggers   
--------------------+-------------------------+------------+------------+------------+----------+-------------
 public             | dbo.Crops               | zktest     |            | t          | f        | f

I have no idea why this error pops up and I have exhausted all capabilities within my limited understanding. I hope someone else sees a possible solution.

解决方案

Perform a select * from pg_tables and see what comes back. That should get you on the right course.

这篇关于关系dbo.MyTable在模式和表确实存在时找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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