如何允许 IIS 使用来自 ASP.NET MVC 项目的本地数据库? [英] How to allow IIS to use local database from ASP.NET MVC project?

查看:22
本文介绍了如何允许 IIS 使用来自 ASP.NET MVC 项目的本地数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在本地网络上演示 ASP.NET MVC 网站.此应用程序与数据库有连接:

I'm going to be demoing a ASP.NET MVC website on a local network. This application has a connection to a database:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)v11.0;AttachDbFilename=|DataDirectory|aspnet-EBC-20141127093222.mdf;Initial Catalog=aspnet-EBC-20141127093222;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

我希望这个数据库是否可以同时被 IIS 使用,并且每当我在本地运行我的应用程序时.我已经在 IIS 上创建了一个站点 - 它运行的是 .NET v4.我的项目位于 c:inetpubwwwebc.我可以发布网站,但在查看页面时收到此错误:

I would like if this database can be used by both IIS and whenever I run my application locally. I've made a site on IIS - it is running .NET v4. My project lives in c:inetpubwwwebc. I can publish the website but recieve this error upon viewing the page:

建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接.(提供程序:SQL 网络接口,错误:50 - 发生本地数据库运行时错误.LocalDB 实例 API 方法调用中发生意外错误.有关错误详细信息,请参阅 Windows 应用程序事件日志."

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Unexpected error occurred inside a LocalDB instance API method call. See the Windows Application event log for error details."

我知道我需要允许通过 microsoft sql server manager 远程连接到 sql server 吗?有没有办法在别处做到这一点?

I know I need to allow remote connections to the sql server through microsoft sql server manager? Is there a way to do it elsewhere?

推荐答案

最好的解决方案是使用 SQL 表达式,但如果您不想,那么您必须执行几个步骤才能使您的 mvc 应用程序与 localdb 一起工作

The best solution is to use SQL Expression but if you don't want there are few steps that you have to do to make your mvc application work with localdb

  1. 以管理员身份打开 Visual Studio 命令提示符
  2. 执行sqllocaldb share v11.0 IIS_DB(然后共享数据库,IIS可以访问)
  3. 将站点连接字符串更改为指向DB的共享实例:Data Source=(LocalDb).IIS_DB 然后再次发布
  1. Open Visual studio command prompt as administrator
  2. execute sqllocaldb share v11.0 IIS_DB (then the database will be shared and IIS can access it)
  3. Change the site connection string to point to the shared instance of DB: Data Source=(LocalDb).IIS_DB then publish again

请注意,此时您可能会收到访问拒绝错误,并有解决方法

Note that in this point you may receive an access deny error and there is how to fix it

  1. 转到visual studio => databaseexplorer => 添加连接
  2. 对于服务器名称输入 (LocalDb).IIS_DB 然后右键单击连接并选择新查询并执行此命令

  1. Go to visual studio => databaseexplorer => add connection
  2. For the server name enter (LocalDb).IIS_DB then right click on the connection and choose new query and execute this command

create login [IIS APPPoolDefaultAPPPool] from windows;
exec sp_addsrvrolemember N'IIS APPPoolDefaultAPPPool, sysadmin

这篇关于如何允许 IIS 使用来自 ASP.NET MVC 项目的本地数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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