在本地IIS上运行时无法连接到数据库 [英] Not able to connect to database when run on Local IIS

查看:92
本文介绍了在本地IIS上运行时无法连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Visual Studio中IIS Express上的asp.net应用程序.该应用程序在IIS express中运行没有任何问题.但是,当我将项目配置切换为在本地IIS上运行时,出现以下数据库错误.

I have an asp.net application which runs on IIS express in visual studio. The application runs without any problems in IIS express. However when I switch the project configuration to run on Local IIS, I get the following database error.

System.Data.SqlClient.SqlException: '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. The specified LocalDB instance does not exist.

当我尝试连接到远程数据库时,这肯定是连接问题,并且可以正常工作.问题是访问本地系统中的数据库.

This is definitely a connectivity problem as I tried connecting to a remote database and it worked. The problem is accessing a database in the local system.

奇怪的是,该应用程序可以在Visual Studio IIS Express上完美运行.

The strange thing is that the application runs perfectly on visual studio IIS express.

我正在使用Windows身份验证,我的连接字符串如下

I am using windows authentication and my connection string is as follows

<connectionStrings>
    <add name="SqlConn" connectionString="Data Source=(localdb)\Projects;Initial Catalog=nga;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>
</connectionStrings>

我尝试根据以下链接修改applicationHost配置

I tried modifying the applicationHost configuration according to the following link

applicationHosts.config文件的内容

Contents of applicationHosts.config file

<applicationPools>
   <add name="DefaultAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
      <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
   </add>
   <add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
   <add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
   <add name=".NET v2.0" managedRuntimeVersion="v2.0" />
   <add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
   <add name=".NET v4.5" managedRuntimeVersion="v4.0" />
   <applicationPoolDefaults managedRuntimeVersion="v4.0">
      <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
   </applicationPoolDefaults>
</applicationPools>

那没有帮助.我想知道外面是否有人可以帮助我.

That did not help. I was wondering if anyone out there could help me.

干杯, 瓦伦

推荐答案

您只需要在SQL Server配置管理器中将"全部收听"设置为是"即可:

You just need to set "Listen All" to yes in the SQL Server Configuration Manager:

这篇关于在本地IIS上运行时无法连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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