Invalid object name dbo.TableName

*爱你&永不变心* 提交于 2019-12-24 00:07:20

问题


I am getting the following error here: http://mvcbense.azurewebsites.net/

Invalid object name 'dbo.BlogPosts'.

This is an MVC3 application using Entity Framework Code First. I have looked elsewhere and have only found something about changing the schema which I assume is what dbo. is.

I am fairly new to EF, but it would look as if EF creates these for me, so I am unsure of what to do. Looking in my local SQL Server Express, all the tables have the dbo. schema on them. Why would I be able to run them locally but not published to Azure?

Thanks


回答1:


The problem is that you haven't configured SQL Azure correctly to migrate your SQL Express based schema first. When you create an ASP.NET Windows Azure Website which is based on local SQL Server, you would have to manually migrate the on-premise DB configured to SQL Azure first and then publish your ASP.NET application to Windows Azure Website. IF you will not do it, your ASP.NET website will not work.

Based on the exception the initial DB tables are missing so what is needed for you is to select any of the suitable database migration method from the list below to migrate your DB first and then run your Windows Azure Website:

Migrating Databases to Windows Azure SQL Database (formerly SQL Azure)




回答2:


A much simpler solution suggested by Stan over here works: http://social.msdn.microsoft.com/Forums/windowsazure/en-US/9c20a99c-80c9-4b1d-afa4-26b9b418f435/connect-to-sql-azure-via-sql-server-management-studio-failed

Excerpt:

  1. cancel out of the first connection dialog that pops up.
  2. click on the New Query button from the toolbar (upper left)
  3. entered Server name: full servername Login: just the username (no @...)
  4. Under Options, Connect to Database, I typed TestDb1
  5. Hit connect.



回答3:


I also experienced the same issue but while using Database first approach. Connection string in my service's/service's host web.config was incorrect. I changed the connection string and it worked.



来源:https://stackoverflow.com/questions/11162631/invalid-object-name-dbo-tablename

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