我在开发阶段使用“真正的”IIS 7.5服务器。该站点指向包含WebProjectDir\App_Data\database.mdf
。
该网站在ApplicationPoolIdentity
下运行,如下所示:
当我运行应用程序时,我收到以下错误:
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
。怎么做?
答案 0 :(得分:2)
该错误与SQL Express有关。
问题是任何通过SQL Express直接连接到MDF文件的帐户都必须具有本地用户配置文件。如果您在该服务器(或其他服务器)上运行完整版本的SQL Server,则应该能够将该MDF文件作为数据库附加并以此方式连接。否则,您的应用程序池必须在具有配置文件的帐户下运行,例如NETWORK SERVICE。
答案 1 :(得分:1)
@Dave,我昨天找到了解决方案。
将Load User Profile
设置为True
会使ApplicationPoolIdentity
能够附加数据库。