简体   繁体   English

如何通过IIS启动SQL Server LocalDB

[英]How to start an SQL Server LocalDB via IIS

I'm using SQL Server LocalDB for a website. 我正在使用SQL Server LocalDB作为网站。

SQL Server LocalDB is installed and a database is created during Setup. 安装SQL Server LocalDB并在安装过程中创建数据库。 A shared instance is created via LocalDBCreateInstance , StartLocalDBInstance and LocalDBShareInstance . 通过LocalDBCreateInstanceStartLocalDBInstanceLocalDBShareInstance创建共享实例。

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. 所以这似乎是某种许可问题。

The application pool runs under the AppPool identity. 应用程序池在AppPool标识下运行。 Switching it to Network Service or Local System does not solve the issue, though. 但是,将其切换到网络服务或本地系统并不能解决问题。

The application pool is configured to load its user Profile and the "setProfileEnvironment" Attribute is also set to true. 应用程序池配置为加载其用户配置文件,“setProfileEnvironment”属性也设置为true。 (Both Settings are required as described here and here ). (这两个设置都是必需的,如此此处所述 )。

I've monitored the database access with the Sysinternal Process Monitor but failed to find any "Access Denied" entries. 我已使用Sysinternal Process Monitor监视数据库访问,但未能找到任何“拒绝访问”条目。

I've also tried to call StartLocalDBInstance from the Website itself (in the Global.asax). 我也尝试从网站本身调用StartLocalDBInstance (在Global.asax中)。 The call returns successfully (return value is S_OK), but the instance is still stopped. 调用成功返回(返回值为S_OK),但实例仍然停止。

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. 这是在IIS下使用LocalDB的缺点 - 该实例由您的交互式登录拥有,并且实例进程只能通过此登录启动。 Since IIS runs as some service account it cannot start LocalDB instance that belongs to your interactive login account. 由于IIS作为某个服务帐户运行,因此无法启动属于您的交互式登录帐户的LocalDB实例。

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

See these two blog posts for more detailed discussion on running LocalDB in full IIS. 有关在完整IIS中运行LocalDB的更详细讨论,请参阅这两篇博客文章。 I would only recommend it for development environment, and use service-based SQL Express for production. 我只推荐它用于开发环境,并使用基于服务的SQL Express进行生产。

  1. Part 1: User Profile 第1部分:用户配置文件
  2. Part 2: Instance Ownership 第2部分:实例所有权

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM