Problem with [SqlException (0x80131904): Invalid object name "dbo.TableName".]

I searched on google and stackoverflow and I did not find an answer, how can I connect to my database table through this 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 the 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 it?

I use mvc and EntityFramework

and the code is as follows:

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 the controller:

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

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

+2
source share
1 answer

I found the answer and it helped!

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

MSSQL: change table owner to dbo using sp_changeobjectowner

Sometimes it becomes necessary to change all the tables in the database that dbo will own for maintenance or to fix random errors. All tables belonging to the dbo schema are usually the best practices in developing database applications using MSSQL, while we can come up with different approaches in real life ...

The next small piece of SQL code goes through all the user tables in the database and changes their owner to dbo. It uses the 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 
+2
source

All Articles