是否可以使ApplicationPoolIdentity附加User Instance = true的数据库?

时间:2011-02-15 15:44:27

标签: asp.net asp.net-mvc iis asp.net-mvc-3 iis-7.5

我在开发阶段使用“真正的”IIS 7.5服务器。该站点指向包含WebProjectDir\App_Data\database.mdf

的Web项目文件夹

该网站在ApplicationPoolIdentity下运行,如下所示:

enter image description here

当我运行应用程序时,我收到以下错误:

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
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: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.

Source Error:

Line 14:         public ActionResult Index()
Line 15:         {
Line 16:             return View(db.Genres.ToList());
Line 17:         }
Line 18: 


Source File: G:\MvcMusicStore\Controllers\StoreController.cs    Line: 16 

我可以通过将应用程序设置为在NetworkService下运行来删除这些错误。但是,如果可以进行任何调整,我想使用ApplicationPoolIdentiy。怎么做?

2 个答案:

答案 0 :(得分:2)

该错误与SQL Express有关。

看一下这个帖子:
http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/527bf46a-b3fe-4ae6-8b41-eb40024399c8/

问题是任何通过SQL Express直接连接到MDF文件的帐户都必须具有本地用户配置文件。如果您在该服务器(或其他服务器)上运行完整版本的SQL Server,则应该能够将该MDF文件作为数据库附加并以此方式连接。否则,您的应用程序池必须在具有配置文件的帐户下运行,例如NETWORK SERVICE。

答案 1 :(得分:1)

@Dave,我昨天找到了解决方案。

Load User Profile设置为True会使ApplicationPoolIdentity能够附加数据库。

enter image description here