problem with [SqlException (0x80131904): Invalid object name 'dbo.TableName'.]

一曲冷凌霜 提交于 2019-11-29 23:22:42

问题


I was looking in google and stackoverflow and i did not find the answer, how can I connect to my database table through that connection string in VS 2010 ?

<add 
  name="ArticleDBContext" 
  connectionString="Data Source=mssql3.webio.pl,2401;Initial Catalog=db_name;Persist Security Info=True;User ID=db_user;Password=passwd;Pooling=False"
  providerName="System.Data.SqlClient"
 />

I always get error: problem with [SqlException (0x80131904): Invalid object name 'dbo.TableName'.]

I know that 'dbo' is SCHEMA , i don't need it, how can I change that ?

i use mvc and EntityFramework

and the code is like this:

in models :

public class Article
{
    public int ID { get; set; }
    public string Title { get; set; }
    public DateTime CreateDate { get; set; }
    public string tekst { get; set; }
}

public class ArticleDBContext : DbContext
{
    public DbSet<Article> Articles { get; set; }
}

and in controller :

public ViewResult Index()
    {
        return View(db.Articles.ToList());
    }

the example is taken from http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part4-cs


回答1:


i found that answer and it helped !

source: http://blogs.x2line.com/al/articles/155.aspx

MSSQL: Change tables owner to dbo with sp_changeobjectowner

Sometimes there is a need to change all tables in the database to be owned by dbo for maintenance or to fix up accidental errors. All tables owned by dbo schema is usually best practices in the database application development with MSSQL while we can meet different approaches in real life...

The following small SQL code snippet goes through all user tables in the database and changes their owner to dbo. It uses sp_changeobjectowner system stored procedure:

DECLARE tabcurs CURSOR
FOR
SELECT 'SOMEOWNER.' + [name]
  FROM sysobjects
 WHERE xtype = 'u'

OPEN tabcurs
DECLARE @tname NVARCHAR(517)
FETCH NEXT FROM tabcurs INTO @tname

WHILE @@fetch_status = 0
BEGIN

EXEC sp_changeobjectowner @tname, 'dbo'

FETCH NEXT FROM tabcurs INTO @tname
END
CLOSE tabcurs
DEALLOCATE tabcurs


来源:https://stackoverflow.com/questions/6015458/problem-with-sqlexception-0x80131904-invalid-object-name-dbo-tablename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!