尝试发布Web应用程序时,应用程序中出现服务器错误。无效的对象名称“ dbo.Employees”

时间:2019-01-28 14:03:47

标签: asp.net-mvc azure deployment azure-web-sites publish

我正在尝试使用Azure在数据库中发布Web应用程序,但遇到了此错误:

Invalid object name 'dbo.Employee'.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 
'dbo.Employee'.

Source Error: 

An unhandled exception was generated during the execution of the current web 
request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

这是我的连接字符串:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-HolidayTracker-20190122013056.mdf;Initial Catalog=aspnet-HolidayTracker-20190122013056;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="LotusWorksEntities" connectionString="metadata=res://*/Models.HolidayTrackerModel.csdl|res://*/Models.HolidayTrackerModel.ssdl|res://*/Models.HolidayTrackerModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-LAKNQGQ\CONORSQL;initial catalog=LotusWorks;user id=sa;password={"mypassword"};MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

我不确定发布时是否正确使用了这些,因为这是我的第一个Web应用程序。它的确发布了,但是每当我使用使用数据库的页面时,都会出现错误。

1 个答案:

答案 0 :(得分:1)

  

异常详细信息:System.Data.SqlClient.SqlException:无效的对象名称   “ dbo.Employee”。

此错误意味着EF使用了名为dbo.Employee的对象(很可能是表),该对象在数据库中不存在。

检查数据库并验证该表是否存在,或者您应该使用其他表名。

另外,根据您的描述,您提供的连接字符串是所有本地Sql数据库。想要发布为天蓝色并查看使用该数据库的页面时,需要使用Azure Sql数据库来提供数据。这是您可以参考的tutorial

设置Azure sql数据库后,选择Use this connection string at runtime(update destination web.config)选项,这样它将使用Azure sql db连接字符串。

enter image description here

相关问题