如何通过IIS启动SQL Server LocalDB [英] How to start an SQL Server LocalDB via IIS

查看:496
本文介绍了如何通过IIS启动SQL Server LocalDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SQL Server LocalDB用于网站。

I'm using SQL Server LocalDB for a website.

安装SQL Server LocalDB并在安装过程中创建数据库。通过 LocalDBCreateInstance 创建共享实例, StartLocalDBInstance LocalDBShareInstance

SQL Server LocalDB is installed and a database is created during Setup. A shared instance is created via LocalDBCreateInstance, StartLocalDBInstance and LocalDBShareInstance.

如果实例启动,网站可以成功连接到数据库。

The website can successfully connect to the database if the instance is started.

但是,如果实例停止,则不会自动启动。从控制台应用程序访问数据库(当实例停止时)会导致实例启动。

However, if the instance is stopped, it is not automatically started. Accessing the database (when instance is stopped) from a console application causes the instance to be started.

所以这似乎是某种权限问题。

So this seems to be some sort of permission Problem.

应用程序池在AppPool标识下运行。但是,将其切换到网络服务或本地系统并不能解决问题。

The application pool runs under the AppPool identity. Switching it to Network Service or Local System does not solve the issue, though.

应用程序池配置为加载其用户配置文件,并且还设置了setProfileEnvironment属性为真。 (两个设置都是必需的这里这里)。

The application pool is configured to load its user Profile and the "setProfileEnvironment" Attribute is also set to true. (Both Settings are required as described here and here).

我使用Sysinternal进程监视器监视数据库访问但未找到任何访问权限拒绝条目。

I've monitored the database access with the Sysinternal Process Monitor but failed to find any "Access Denied" entries.

我还试图打电话给 StartLocalDBInstance (在Global.asax中)。调用成功返回(返回值为S_OK),但实例仍然停止。

I've also tried to call StartLocalDBInstance from the Website itself (in the Global.asax). The call returns successfully (return value is S_OK), but the instance is still stopped.

推荐答案

这是使用LocalDB下的缺点IIS - 实例由交互式登录拥有,实例进程只能通过此登录启动。由于IIS作为某个服务帐户运行,因此无法启动属于您的交互式登录帐户的LocalDB实例。

That's the drawback of using LocalDB under IIS - the instance is owned by your interactive login, and the instance process can only be started by this login. Since IIS runs as some service account it cannot start LocalDB instance that belongs to your interactive login account.

您可能使用IIS服务帐户拥有的LocalDB实例,但请注意您可能会遇到用户配置文件问题 - LocalDB需要创建和加载用户配置文件,而IIS使用有时可能无法完全创建和加载的轻量级用户配置文件。

You might use a LocalDB instance owned by IIS service account, but be aware that you might run into user profile issues - LocalDB requires the user profile to be created and loaded, while IIS uses lightweight user profiles that sometimes may not be fully created and loaded.

有关在完整IIS中运行LocalDB的更详细讨论,请参阅这两篇博客文章。我只推荐它用于开发环境,并使用基于服务的SQL Express进行生产。

See these two blog posts for more detailed discussion on running LocalDB in full IIS. I would only recommend it for development environment, and use service-based SQL Express for production.


  1. 第1部分:用户档案

  2. 第2部分:实例所有权

  1. Part 1: User Profile
  2. Part 2: Instance Ownership

这篇关于如何通过IIS启动SQL Server LocalDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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