[转载]VS2015自带的LocalDB数据库实例在IISExpress运行成功却在IIS中运行失败的解决方案
前言:
开发工具:Visual Studio 2015 Update 2.
数据库:Sql Server LocalDB V13 Express.
系统:Windows 10.
.NET Framework:4.6.1.
我一开始安装的是Visual Studio 2015 Update 1,后面升级到Visual Studio 2015 Update 2.
所以我的Visual Studio 2015中的Sql Server对象资源管理器窗口那里有两个连接实例:
一个是(localdb)\MSSQLLocalDB(v12.0.2000.8).
另外一个是(localdb)\ProjectsV13(v13.0.1100).
现在,我使用Entity Frameworkk 6连接(localdb)\ProjectsV13实例。
直接在Visual Studio 2015 F5调试运行(默认采用IISExpress),项目正常运行,而当我部署在IIS中,却运行失败。
总之提示连接不到数据库之类的相关错误。
我在IIS中添加了个网站,命名为:Allen.Fast.Web;创建的应用程序池,也命名为:Allen.Fast.Web.
Allen.Fast.Web应用程序池使用集成模式运行,注意,身份标识使用的是:ApplicationPoolIdentity。
解决方案:
Using LocalDB with Full IIS, Part 1: User Profile
Using LocalDB with Full IIS, Part 2: Instance Ownership
以上是解决LocalDB在IIS中的运行问题的可能的解决方案,记录一下,以备查用。
******
我最喜欢的解决方案:
1、在命令行中启用共享LocalDB连接(需要管理员权限):
sqllocaldb share ProjectsV13 ProjectsV13Share
2、使用Microsoft SQL Server Management Studio连接LocalDB测试是否成功:
服务器名称:(localdb)\.\ProjectsV13Share
身份验证:Windows身份验证
3、新建查询,为IIS应用程序池添加登录和数据库权限:
create login [IIS APPPOOL\Allen.Fast.Web] from windows; exec sp_addsrvrolemember N'IIS APPPOOL\Allen.Fast.Web', sysadmin
(注:具体应用程序池请根据需要修改)
4、修改连接字符串的data source属性:
原:data source=(LocalDB)\ProjectsV13
改:data source=(LocalDB)\.\ProjectsV13Share;
5、OK了!
出处:http://www.cnblogs.com/vallen
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
唯有偏执者得以生存。