SqlException:对象名称dbo无效.使用LocalSystem作为标识时 [英] SqlException: Invalid object name dbo.<tablename> when using LocalSystem as Identity
问题描述
我在本地IIS(7.0)上部署了一个asp.net Web API,但无法访问数据库.
I deployed a asp.net web api on my local IIS (7.0) and I can't get through in accessing the database.
当身份(在过程模型下)设置为 LocalSystem
时,API将返回此异常:
When the identity (under process model) is set to LocalSystem
, API will return this exception:
无效的对象名称'dbo.tablename'
Invalid object name 'dbo.tablename'
如果我将身份设置为 ApplicationPoolIdentity
,则API将返回此异常:
If I set the identity to ApplicationPoolIdentity
, the API will return this exception:
无法打开登录请求的数据库"dbname".登录失败.用户'IIS APPPOOL \ ASP.NET v4.0'登录失败.
Cannot open database "dbname" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
尝试过的解决方案:
https://www.youtube.com/watch?v=18-zatWd68s
已将文件夹和.mdf文件的权限添加到"ASP.NET v4.0"
Added permissions to both folder and .mdf file to 'ASP.NET v4.0'
其他相关信息:
连接字符串(在 web.config
中)
<add name="DbContext"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=[dbname];Trusted_Connection=Yes;"
providerName="System.Data.SqlClient" />
我还尝试使用IIS Express在Visual Studio中运行应用程序,效果很好.
I also tried running the application using Visual Studio using IIS Express, it worked fine.
推荐答案
您已经看到它说您基本上有3个选择,
It says you basically have 3 options,
- 将IIS作为您的ID(不好的主意),
- 将localdb作为共享实例运行,或者
- 使用SQL Express
后者可能是最好的建议.
The latter is probably the best advice.
这篇关于SqlException:对象名称dbo无效.使用LocalSystem作为标识时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!