SQLExpress connection fails in IIS 7 w/ user instance error - \"Failed to generate a user instance

时间秒杀一切 提交于 2019-12-04 17:24:37

You are using a connection string with trusted authentication = true. This means that the connection uses the security context of the calling process.

When you run with the development server you are running in the security context of the logged in user, so every thing works fine.

When you run in IIS you are in the security context of the application pool process, which is NETWORK SERVICE, which does not have a user profile, therefore it crashes.

You can fix it by either:

  • Change the identity of the application pool to a normal user with access to the database
  • Use a connection string with user name and password

IIS doesn't load the Windows user profile, but certain applications might take advantage of it anyway to store temporary data. SQL Express is an example of an application that does this. However, a user profile has to be created to store temporary data in either the profile directory or in the registry hive. The user profile for the Network Service account was created by the system and was always available. However, with the switch to unique Application Pool identities, no user profile is created by the system. Only the standard application pools (DefaultAppPool and Classic .NET AppPool) have user profiles on disk. No user profile is created if the Administrator creates a new application pool.

However, if you want, you can configure IIS application pools to load the user profile by setting the LoadUserProfile attribute to "true".

https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities

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