发布 IIS 时连接到 DB.mdf 时出错 [英] Error Connecting to DB.mdf when published IIS

查看:20
本文介绍了发布 IIS 时连接到 DB.mdf 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索不同的资源来解决我的问题.我在 IIS 上发布了一个我一直在开发的网站,这是我在 IIS 上发布的第一个网站.

我似乎无法连接到数据库.

我会在这里提供我所做的一切..

感谢任何帮助....

我的 web.config 文件位于已发布网站目录 C:\FinancialHubTest 中.在旁注中,我还尝试将 User Instance=True 添加到我的 web.config 文件中的连接字符串,但它不起作用..

<!--<add name="ConnStr" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFileName=|DataDirectory|\FinancialHub.mdf;Integrated Security=True"/>--><add name="ConnStr"connectionString="Data Source=(LocalDB)\.\IIS_DB;Integrated Security=True;"/></connectionStrings>

来自cmd的MSSQLLocalDB的详细信息

C:\Windows\System32\inetsrv\config 中的applicationHost 文件用Notepad2 编辑.我使用 FinancialHub 作为我在 IIS 中发布的网站的 applicationPool

我的 SQL Server 对象资源管理器,只有当我通过 Visual Studio 2015 运行我的网站时才会出现连接,我认为它会在 IIS Express 上运行..

每次我在这里和那里更改时都会收到此错误,但我真的很确定原因.. 或者更确切地说,我对 web.config 等所做的更改会导致此错误.我也检查了 Windows 事件日志.

我也关注了这两个关于处理这个问题的链接,

在完整的 IIS 中使用 LocalDB,第 1 部分:用户配置文件

在完整的 IIS 中使用 LocalDB,第 2 部分:实例所有权

如果需要更多信息,我可以提供..

我觉得我一直在绕圈子想弄清楚,但我似乎无法解决它..

我真的很感激任何帮助.非常感谢.

解决方案

即使将应用程序发布到 IIS,您仍在使用 LocalDB.LocalDB (App_Data 内的 SQL 数据库) 主要仅用于开发和测试目的.

当您在 IIS 上托管站点时,您需要一个真正的 SQL Server.因此,您需要在托管应用程序的同一台服务器或专用 SQL 服务器中安装 SQL Server.然后将现有数据库附加或复制到 SQL Server.

I have been searching all over different sources in search on solving my issue.. I've published a website on IIS that I have been working on and this is my first published website on IIS.

I seem to not be able to connect to the database.

I will provide everything that I have done right down here..

Appreciate any help please....

My web.config file in the published website directory C:\FinancialHubTest. On a side note I also tried adding User Instance=True to my connection string in my web.config file but it doesn't work..

<connectionStrings>
    <!--<add name="ConnStr" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFileName=|DataDirectory|\FinancialHub.mdf;Integrated Security=True" />-->
    <add name="ConnStr" 
         connectionString="Data Source=(LocalDB)\.\IIS_DB;Integrated Security=True;" />
</connectionStrings>

Details of MSSQLLocalDB from cmd

applicationHost file in C:\Windows\System32\inetsrv\config edited with Notepad2. I'm using FinancialHub as my applicationPool for my published website in IIS

<applicationPools>
        <add name="DefaultAppPool" managedRuntimeVersion="v4.0" />
        <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="FinancialHub" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
          <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
        </add>
        <applicationPoolDefaults managedRuntimeVersion="v4.0">
            <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
        </applicationPoolDefaults>
    </applicationPools>

My Published Website directory with App_Data having the FinancialHub.mdf file

My SQL Server Object Explorer, the connection only appears when I run my website via Visual Studio 2015 I think that would be running on IIS Express..

I have been getting this error every time I change here and there but I'm really sure why.. Or rather what changes I make to either web.config, etc will cause this error. I check the windows event log too.

I also followed these 2 links on dealing with this issue,

Using LocalDB with Full IIS, Part 1: User Profile,

Using LocalDB with Full IIS, Part 2: Instance Ownership

If there is a need for more information i can provide..

I feel like i have been beating around the bush trying to figure out but i can't seem to solve it..

I really do appreciate any help please. Thank you so much.

解决方案

You are still using LocalDB even after publishing the application to IIS. LocalDB (SQL Database inside App_Data) is primarily intended for developing and testing purpose only.

You need a real SQL Server when you host the site on IIS. So you need to install SQL Server either in the same server that the application is hosted or a dedicated SQL server. Then attach or copy the existing database to SQL Server.

这篇关于发布 IIS 时连接到 DB.mdf 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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