0

I have just uploaded my MVC3 ASP.net web application to my server 2008 R2 IIS 7.5 Express webserver.

The web app loads fine, but when clicking on the logon link and either trying to register a user account or log a existing user account on I get the following error:

"Sorry, an error occurred while processing your request."

If I browse the web app on my webserver (from within IIS7.5) and try the logon link I get the following ASP error:

"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: 26 - Error Locating Server/Instance Specified)"

"Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code."

"Exception Details: 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: 26 - Error Locating Server/Instance Specified)"

"Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below."

Would someone mind helping me trouble shoot please?

I have two databases configured in my Web.Config:

<connectionStrings>
    <add name="DatabaseDBContext" connectionString="data source=|DataDirectory|Content_Database.sdf" providerName="System.Data.SqlServerCe.4.0"/>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>

The SQL Compact (Content_Database.sdf) database works fine. I only get the error when trying to access the aspnetdb.mdf database.

The ASPNETDB.mdf database is practically in identical state to what you get given when loading the Microsoft MVC3 Razor template / tutorial from Visual Web Developer Express 2010.

I tried installing SQL Express 2008 on my webserver just in case this was the issue, made no difference.

The whole web application works perfectly on my Visual Web Developer 2010 Express development server (I can create users and log them on and off successfully). It just fails as soon as it is uploaded to the webserver.

Help appreciated - many thanks :-)

Full Web.Config:

    <?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->

<configuration>
  <connectionStrings>
      <add name="DatabaseDBContext" connectionString="data source=|DataDirectory|\Content_Database.sdf" />
      <add name="ApplicationServices" connectionString="data source=|DataDirectory|\aspnetdb.sdf" />

      <!--<add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />-->
  </connectionStrings>

  <appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Admin/LogOn" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
            <add name="SqlCeMembershipProvider" type="Project1.Domain.SqlCeMembershipProvider" connectionStringName="ApplicationServices" applicationName="/"
         enablePasswordRetrieval="false" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" writeExceptionsToEventLog="false" />
            <!--<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />-->
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager defaultProvider="SqlCeRoleProvider"
             enabled="true"
             cacheRolesInCookie="true"
             cookieName=".ASPROLES"
             cookieTimeout="30"
             cookiePath="/"
             cookieRequireSSL="false"
             cookieSlidingExpiration="true"
             cookieProtection="All">
      <providers>
        <clear/>
          <add name="SqlCeRoleProvider" type="System.Web.Security.SqlCeRoleProvider" connectionStringName="ApplicationServices" applicationName="/" writeExceptionsToEventLog="true" />
        <!--<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />-->
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration

>

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Harry
  • 735
  • 5
  • 16
  • 27

1 Answers1

0

It looks like your DatabaseDBContext/SDF if a Sql Compact database. This engine is extremely different from an administrators point of view. Basically, it is very simple to setup and get working.

Your ApplicationServices/mdf file is not a Compact database, it uses the normal sql (express, dev, workgroup, standard, enterprise etc) engine. This does require a bit of tweaking to get working. Your data source= option is configuring the SqlClient to use a specific engine installed on the local machine to open the database (this would require sql to be installed on the local machine as an instanced install with the name SqlExpress) and properly configured to allow connections (possibly remote). The Integrated Security is configuring the SqlClient to connect to the server as the user configued in the AppPool to connect to the database, which requires that user to have access to the file where the database is stored, the database itself (inside as security), and all the other security requirements of SSPI (which I would highly recommend you keep).

Update

I have a few projects running exclusively on Compact Framework (because for small projects, it's so much easier to maintain/administer).

To use SQL Server Compact 4, you need to install the Visual Studio Tools for SQL Server Compact 4. I use erikej SQL Compact Providers (Membership and Role) for asp.net and haven't run into any issues. The nice part about the providers is that most of the code you've written against the current providers won't change, you're just replacing the provider and database.

Either way, happy coding!

Update 2

My web.config has the following entries:

<connectionStrings>
 <add name="membershipDatabase" 
      connectionString="data source=|DataDirectory|\Membership.sdf" />
</connectionStrings>

<membership defaultProvider="SqlCeMembershipProvider">
  <providers>
    <clear />
    <add name="SqlCeMembershipProvider" 
         type="Project1.Domain.SqlCeMembershipProvider"           
         connectionStringName="membershipDatabase" 
         applicationName="/" 
         enablePasswordRetrieval="false" 
         requiresQuestionAndAnswer="false" 
         requiresUniqueEmail="true" 
         passwordFormat="Hashed"  
         writeExceptionsToEventLog="false" />
  </providers>
</membership>
<roleManager defaultProvider="SqlCeRoleProvider" 
             enabled="true" 
             cacheRolesInCookie="true" 
             cookieName=".ASPROLES" 
             cookieTimeout="30" 
             cookiePath="/" 
             cookieRequireSSL="false" 
             cookieSlidingExpiration="true" 
             cookieProtection="All">
  <providers>
    <clear />
    <add name="SqlCeRoleProvider" 
         type="Project1.Domain.SqlCeRoleProvider" 
         connectionStringName="membershipDatabase" 
         applicationName="/" 
         writeExceptionsToEventLog="true" />
  </providers>
</roleManager>
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • Thank you very much for the help Erik. I do indeed run two different databases. When initially running the tutorial the template for the web aplication comes with the ability to register users and log them on and off built in. This uses the "aspnetdb.mdf" database by standard. When creating the other database the tutorial talked us though creating a SQL Compact database. – Harry Apr 17 '12 at 21:33
  • This seems to work out the box, and ideally I'd like to use .sdf files through out the web application - however I've no idea how or where to begin to change the applications functionality to use SQL compact as the database controlling the creation of users and allowing them to authenticate. I will re-vist my webserver and check that SQL Express is installed correctly. – Harry Apr 17 '12 at 21:36
  • Thank you once again Erik - would you mind helping me with how I might modify my webconfig so as it uses a SQL CE database for the aspnetdb database? Would I simply change the connection string so it reads: " ?? Is there anything else I'll need to change in my web app code? – Harry Apr 18 '12 at 09:36
  • note: I did try the above, but it failed miserably - the existing SQL CE database (Content_Database.sdf) is being read by the web application no problem - I get no errors when accessing the part of the site that reads information from that database. – Harry Apr 18 '12 at 09:38
  • Thanks Erik, unfortunately that web.config doesn't want to work with my project (changing the connection string to suit my code of course). Also it throws an error: "Error parsing the web configuration at line 8. A document must contain exactly one root element." I will update my original question with my entire Web.Config file. Thanks. – Harry Apr 19 '12 at 08:24
  • I need the web.config that doesn't work in order to solve your specific problem. – Erik Philips Apr 19 '12 at 15:55
  • Hi Erik, the web.config that doesn't work is your version that you gave me above, only I changed the name and database name to match what I have referenced in my code (e.g. for the main content and for the user account database – Harry Apr 19 '12 at 20:20
  • The one listed is not a complete web.config, only the parts I use for asp.net membership. The error message you listed is that the XML is not valid for some reason, which I wouldn't be able to deuce based on my XML which is only a partial web.config. – Erik Philips Apr 19 '12 at 22:02
  • Thanks again Erik, I've updated my web.config above with your edits. New error on line 68: **Parser Error Message:** Could not load type 'System.Web.Security.SqlCeRoleProvider'. – Harry Apr 20 '12 at 12:22
  • 1
    You need to do some research as to how assemblies are used and created. There is no `System.Web.Security.SqlCeRoleProvider`, as that is an assumption it came from microsoft which I had originally posted, it did not. I also did post the the `SqlCeRoleProvider` in question should be part of the project itself as stated with `Project1.Domain.SqlCeRoleProvider` being the namespace and class, which is available from in my first update, but needs to be modified (namespace) to fit the web.config configuration. – Erik Philips Apr 20 '12 at 23:09