加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 部署后SQL不会连接

发布时间:2020-12-16 03:24:27 所属栏目:asp.Net 来源:网络整理
导读:我最近在IIS(LocalDB)上部署了我的网站.但每当我尝试运行网站时,SQL都无法连接.我现在已经浏览了数百个帖子/文章,但我无法解决它. 错误 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server
我最近在IIS(LocalDB)上部署了我的网站.但每当我尝试运行网站时,SQL都无法连接.我现在已经浏览了数百个帖子/文章,但我无法解决它.

错误

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.
Cannot create an automatic instance. See the Windows Application event
log for error details. )

Windows应用程序事件日志

Windows API call SHGetKnownFolderPath returned error code: 5. Windows
system error message is: Access is denied. Reported at line: 422.

第二个日志 –

Cannot get a local application data path. Most probably a user profile
is not loaded. If LocalDB is executed under IIS,make sure that
profile loading is enabled for the current user.

我的连接字符串(试过两个) –

<appSettings>
    <add key="ConnectionString" value="Data Source=(LocalDB)MSSQLLocalDB;Initial Catalog=test;Integrated Security=True" />
    <!--<add key="ConnectionString" value="data source=(LocalDB)MSSQLLocalDB;UID=SOME_USERNAME;PWD=SOME_PASSWORD;initial catalog=test;connection timeout=30"/>-->
  </appSettings>

我试过编辑applicationHost.config.
Load User Profile对我来说已经是真的了

我的ApplicationHost.config文件

<applicationPools>

            <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" />
            <add name="ASP.NET v4.0" managedRuntimeVersion="v4.0">

            <add name="DefaultAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
           <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
            </add>
        </applicationPools>

我的IIS经理 –

enter image description here

DefaultApplicationPool –

enter image description here

我的网络应用配置 –

enter image description here

应用池权限

enter image description here

编辑 –

使用添加IIS Apppool

icacls c:inetpubwwwroot /grant "IIS APPPOOLDefaultAppPool":(OI)(CI)(RX)

仍然无法连接.

任何帮助表示赞赏.

我使用Visual Studio 2015和SQL Server 2016在Windows 10上.

解决方法

有同样的问题.不过,我没有尝试过你所做的所有事情.我做了以下事情:

> IIS管理器>应用程序池>找到您的应用所属的池(对我而言,它是.NET v4.5)>右键单击 – >高级设置>向下滚动到Identity>将任何(对我而言,ApplicationPoolIdentity,与您相同)更改为LocalSystem.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读