问题
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:
Login failed for user 'IIS APPPOOL\ASP.NET v4.0'
https://www.youtube.com/watch?v=18-zatWd68s
Added permissions to both folder and .mdf file to 'ASP.NET v4.0'
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