IIS 7中的SQLExpress连接失败,用户实例错误 - “无法生成用户实例 [英] SQLExpress connection fails in IIS 7 w/ user instance error - "Failed to generate a user instance

查看:212
本文介绍了IIS 7中的SQLExpress连接失败,用户实例错误 - “无法生成用户实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要是想回答下面我的问题#1,但是会有更多的知识。



我在调查过程中尝试使用这些资源但是没有成功:





====================



如果要求,将提供更多证据。

解决方案

您正在使用带有trusted authentication = true的连接字符串。这意味着连接使用调用进程的安全上下文。



当您使用开发服务器运行时,您正在登录用户的安全上下文中运行,因此一切正常。



当您在IIS中运行时,您处于应用程序池进程的安全上下文中,即NETWORK SERVICE,它没有用户配置文件,因此它会崩溃。



您可以通过以下方式修复:




  • 更改应用程序池的标识给可以访问数据库的普通用户

  • 使用带有用户名和密码的连接字符串


Mainly looking to answer my question #1 below, but more knowledge would be appreciated.

I tried to use these resources during my investigation, but was unsuccessful:

http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/f5eb164d-9774-4864-ae05-cac99740949b (For this error: 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.)

http://social.msdn.microsoft.com/forums/en-US/sqlexpress/thread/6dfdcc22-7a81-4e8f-a947-c1ce6982d4b3/ (For this error: CREATE DATABASE permission denied in database master. An attempt to attach an auto-named database for file ? failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.)

Questions

1.) Why does this error occur while running the Telerik Rad Controls for ASP.NET AJAX "Live Demos" project with IIS 7 (Running Telerik Live Demos works fine using ASP.NET Development Server with this connection string)

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.

2.) How is creating a SQL Server Express instances different in IIS 7, from ASP.NET Development Server & SSMSE

3.) Are there certain attributes of a SQL connection string not allowed when running a website on different contexts (based on #2).

Environment:

I'm not running the "Live Demos" .NET 3.5 ASP.NET web application via the ASP.NET Development Server (feature that pops up in your system tray and picks a port for you after clicking play in Visual Studio). That works just fine! I'm running the website on IIS 7. SQL Server Express is using the NETWORK SERVICE user in Control Panel > Administrative Tools > Services > SQL Server (SQLExpress).

Using this connection string provided with the installed "Live Demos" web application demo project:

<add name="NorthwindConnectionString"
             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=True"
             providerName="System.Data.SqlClient" />

I've tried setting "User Instance=False", but that just throws another error:

CREATE DATABASE permission denied in database master. An attempt to attach an auto-named database for file ? failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

(where "?" is the path of the *.mdf file - C:\Users\\MyDocuments\Visual Studio 2008\Projects\TelerikDemos\Telerik\RadControls for ASP.NET AJAX Q2 2011\Live Demos\App_Data\Northwind.mdf .. Stack Overflow italics is broken with some of those characters, so I had to remove that path)

Someone answered me on a previous question to set this "User Instance=False", but it appears User instances have nothing to do with whether or not you use SQL Express. User Instances are simply a feature of SQL Express that allows a very unprivileged user to host a database instance in it's own user context.

Note, this Northwind database is stored in an *.mdf file in the App_Data folder (under the "Live Demos" root application directory) along with the *.ldf (log file). I did previously try attaching the *.mdf files as actual databases under the "Databases" folder (in the SSMSE Object Explorer tree), but later removed them.

Web application "Live Demos" root folder (and nested folders/files) have the following users assigned with ALL privileges:
- IIS APPPOOL\Telerik ("Telerik" is the name of my application pool in IIS 7 for this site)
- IUSR
- NETWORK SERVICE

Making a note for myself about this SQLExpress master database query:

SELECT * FROM sys.dm_os_child_instances

Also tried different combinations of *.mdf & *.ldf permissions while also changing the user on the SQL Server (SQLExpress) Windows 7 service (Control Panel > Administrative Tools > Services) .. and also restarted the service after making those changes.

To reproduce:

download the Telerik Rad Controls for ASP.NET AJAX. Set the permimssions I mentioned in the "Live Demos" folder under Program Files\Telerik, change the .NET version of the web application to .NET 3.5, switch out their 3.5 web.config file with the normal web.config file in that folder. You have to use Visual Studio 2010, but I am running this in Visual Studio 2008 (with a little grunt work I did because our company is not yet on VS2010). Also switch out the proper Bin35 assemblies into the "Live Demos" folder Bin folder. Compile the solution. Create an IIS 7 website. Add Windows authentication. Enabled anonymous and Windows authentication.. all others are disabled. Set application pool to use Classic and 32 bit.

Then navigating to this URL and clicking the "First Look" image.

http://localhost/combobox/examples/overview/defaultcs.aspx

====================

More evidence will be provided if requested.

解决方案

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 7中的SQLExpress连接失败,用户实例错误 - “无法生成用户实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆