SqlException: Invalid object name dbo.<tablename> when using LocalSystem as Identity

允我心安 提交于 2019-12-11 14:08:48

问题


I deployed a asp.net web api on my local IIS (7.0) and I can't get through in accessing the database.

When the identity (under process model) is set to LocalSystem, API will return this exception:

Invalid object name 'dbo.tablename'

If I set the identity to ApplicationPoolIdentity, the API will return this exception:

Cannot open database "dbname" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

Solutions tried:

  1. Login failed for user 'IIS APPPOOL\ASP.NET v4.0'

  2. https://www.youtube.com/watch?v=18-zatWd68s

  3. Added permissions to both folder and .mdf file to 'ASP.NET v4.0'

  4. https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-2-instance-ownership/

Other relevant information:

connection string (in web.config)

<add name="DbContext" 
     connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=[dbname];Trusted_Connection=Yes;" 
     providerName="System.Data.SqlClient" />

I also tried running the application using Visual Studio using IIS Express, it worked fine.


回答1:


You've already seen https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-2-instance-ownership/

It says you basically have 3 options,

  • run IIS as your ID (bad idea),
  • run localdb as a shared instance, or
  • use SQL Express

The latter is probably the best advice.



来源:https://stackoverflow.com/questions/34981518/sqlexception-invalid-object-name-dbo-tablename-when-using-localsystem-as-iden

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