-1

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

MSSQLLocalDB

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

mdf

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..

sql

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.

errorsql

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
domster
  • 556
  • 2
  • 8
  • 26
  • 1
    Do *not* upload *pictures* of code. We can't do anything with it, and anyone attempting to help you would have to type everything back out again. It makes as much sense as taking a picture of your car to a mechanic and asking them to tell you what's wrong. – Siyual Jul 28 '17 at 14:53
  • Siyual do you happen to have any solution to my problem? Thank you for the edit @marc_s – domster Jul 28 '17 at 15:03

1 Answers1

1

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.

Win
  • 61,100
  • 13
  • 102
  • 181
  • So i have to use something like this in my connectionstring? Data Source=.\SQLEXPRESS;Initial Catalog=OldFashionedDB;Integrated Security=True May i know if there's any guide that i can follow? – domster Jul 28 '17 at 14:58
  • SQLExpress is fine for testing. You will need to update that connection string pointing to the SQLExpress. – Win Jul 28 '17 at 15:00
  • it's not possible to get App_Data working in my local hosted website with MSSQLLocalDB? – domster Jul 28 '17 at 15:01
  • 1
    There are few ways to hack it. However, you *should not* be using LocalDb other than your local computer. You should use at least *SQL Express* for testing. – Win Jul 28 '17 at 15:02
  • If i were to use LocalDB may i ask how do i? I am flexible to switch to SQL Express too... – domster Jul 28 '17 at 15:03
  • [How to allow IIS to use local database from ASP.NET MVC project?](https://stackoverflow.com/a/27326552/296861) – Win Jul 28 '17 at 15:06
  • Im freaking out because my final presentation for my project is closing in.. it's really odd how i followed through everything online but doesnt work. – domster Jul 28 '17 at 15:08
  • 1
    It is not worth hack to use LocalDb. Easiest and fastest way is to use SQLExpress. If you error connecting SQL Express, look at [Why am I getting “Cannot Connect to Server - A network-related or instance-specific error”?](https://stackoverflow.com/a/18060818/296861). – Win Jul 28 '17 at 15:10
  • I'll switch to SQLExpress then.. Im actually still working on my website on normal LocalDB and using Visual Studio 2015 running on IIS Express then i'll publish it a day before my presentation.. May i ask if there's source where i can use SQL Express? I saw somewhere it's basically using SQL Express to connect to LocalDB or something.. – domster Jul 28 '17 at 15:12
  • i'll get back here once i've created the SQLExpress DB. Thank you for your comment (will upvote to indicate which one). – domster Jul 28 '17 at 15:48