locked
Issues with MVC ASP.NET Membership and SQL RRS feed

  • Question

  • User2012297617 posted

    I recently deployed an  MVC website and I’m using godaddy for hosting.  I setup the database using their SQL Server portal. I can see data. My problem is when I try to login or register. I’m having issues trying to access the membership. Please see my web.config file below.  

    The error is 

    The system cannot find the file specified 
    Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
      <!--
      <add name="EFDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=PlayGround;Integrated Security=true" providerName="System.Data.SqlClient" />
      -->
       <remove name="LocalSqlServer" />
      <add name="EFDbContext" connectionString="Data Source=playground.db.9999999.hostedresource.com;  Initial Catalog=playground; User ID=playground; Password=mypassword; " providerName="System.Data.SqlClient"  />
    
      </connectionStrings>
    
    
      
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <authentication mode="None" />
        <compilation targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
        <trust level="Full"/> 
       
      </system.web>
      <system.webServer>
        <modules>
          <remove name="FormsAuthentication" />
        </modules>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
         
        </providers>
      </entityFramework>
      <system.codedom>
    
      </system.codedom>
    </configuration>

    Saturday, December 3, 2016 3:48 PM

Answers

  • User2012297617 posted

    I got it to work!  Even though I had the same connection setting, for some reason by naming the connection "DefaultConnection" worked.

    I used this connection:

    <add name="DefaultConnection" connectionString="Data Source=myLocations.db.999999.hostedresource.com;
    Initial Catalog=myLocations; User ID=myLocations; Password='your password';"providerName="System.Data.SqlClient" />

    For more reference, see this article: http://httpjunkie.com/2014/954/using-godaddy-sql-server-w-asp-net-mvc5-code-first/

    Thanks for your help on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 14, 2016 3:39 AM

All replies

  • User753101303 posted

    Hi,

    You mean https://msdn.microsoft.com/en-us/library/6e9y4s5t.aspx ? For now it doesn't seems to be configured. Are you sure it does use the expected database even on your own local machine?

    I would do a test page to show some configuration details suign https://msdn.microsoft.com/en-us/library/system.web.security.membership(v=vs.110).aspx (suhc as the list of providers for example) and then  fix the config to match what I want...

    Sunday, December 4, 2016 9:34 AM
  • User2012297617 posted
    Hi, yes... it works on my local machine. I'm able to register and login to my account. I'm using MVC 5. I tried to query the database in sql to see my account, but I never found it. Where does it get stored?
    My issue might be a configurartion setting in the web.config file that I got in the godaddy server. In my local environment works fine.
    Sunday, December 4, 2016 2:23 PM
  • User932909087 posted

    Hi lesponce,

    The connection string is incorrect. Please check it again or please ask their support the connection string that you need to use

    Monday, December 5, 2016 5:30 AM
  • User-2057865890 posted

    Hi Lesponce,

    Change the web config setting of defaultConnectionFactory.

     <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="Data Source=playground.db.9999999.hostedresource.com;
    Initial Catalog=playground; User ID=playground; Password=mypassword;" /> </parameters> </defaultConnectionFactory> </entityFramework>

    reference:

    https://blogs.msdn.microsoft.com/davidobando/2012/08/14/changing-efs-default-connection-factory-from-localdb-to-sql-server/

    http://stackoverflow.com/a/34797291 

    https://msdn.microsoft.com/en-us/library/jj556606(v=vs.113).aspx 

    Best Regards,

    Chris

    Monday, December 5, 2016 7:44 AM
  • User2012297617 posted

    Thanks Chris,.  Unfortunately, I'm still getting the same error. 

    Tuesday, December 6, 2016 1:28 AM
  • User2012297617 posted

    Well, I didn't notice "SqlConnectionFactory" on the line below.  

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">

    Now I'm getting permission issues. I'm getting closer.

    System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.

    Tuesday, December 6, 2016 3:25 AM
  • User-2057865890 posted

    Hi Lespoce,

    System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.

    Seems like your credentials in the connection string should have permission to create database on your server. Log in to your database server and check whether your user account has the correct permissions.

    reference: http://blog.sqlauthority.com/2008/12/27/sql-server-add-any-user-to-sysadmin-role-add-users-to-system-roles/ 

    Best Regards,

    Chris

    Tuesday, December 6, 2016 5:21 AM
  • User2012297617 posted

    I'm using my hosting provider's SQLServer.  I wonder if my issue is related to the DBContext?   Should I use something like this?  I see this worked for some people.  Database.SetInitializer<EFDbContext >(null);

    using Playground.Domain.Entities;
    using System.Data.Entity;
    
    namespace Playground.Domain.Concrete
    {
        public class EFDbContext : DbContext
        {
            public DbSet<Article> Articles{ get; set; }
        }
    }
    
    
    
    

    Tuesday, December 6, 2016 12:27 PM
  • User-2057865890 posted

    Hi Lesponce,

    public class EFDbContext : DbContext
    {
       public EFDbContext() : base("name=EFDbContext")
       {
       }
       public DbSet<Article> Articles{ get; set; }
    }

    reference: http://www.entityframeworktutorial.net/code-first/database-initialization-in-code-first.aspx 

     Database.SetInitializer<EFDbContext >(null);

    At times you may want to use an existing database with Code First. If you may not want to execute any initialization logic at all. You can suppress the database initialization process altogether by passing null to SetInitializer() method.

    reference: http://www.codeguru.com/csharp/article.php/c19999/Understanding-Database-Initializers-in-Entity-Framework-Code-First.htm 

    Best Regards,

    Chris

    Wednesday, December 7, 2016 2:48 AM
  • User2012297617 posted

    I tried to add the line below to my Global.asax file and I'm still getting the same problem.

    Database.SetInitializer<MyDBContext>(null);

    Thursday, December 8, 2016 2:29 AM
  • User2012297617 posted

    I just tried your suggestion and still same problem. :(

       public EFDbContext() : base("name=EFDbContext")
       {
       }
    Thursday, December 8, 2016 2:57 AM
  • User-2057865890 posted

    Hi Lesponce,

    If the problems are permission related, have you tried putting login account in the sysadmin server role?

    http://odetocode.com/blogs/scott/archive/2012/08/15/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx 

    Best Regards,

    Chris

    Thursday, December 8, 2016 9:56 AM
  • User2012297617 posted

    Hi, I think it maybe related to permission issue. The thing is that I'm trying to figure out  the GoDaddy's SQL Server Web Portal console. It's not that I'm dealing with a Windows server directly.  The error that I'm getting now is: 

     System.Data.SqlClient.SqlException: Login failed for user 'PHXxxxxx\Iusr_xxxxxxxxx'.

    Tuesday, December 13, 2016 12:54 PM
  • User2012297617 posted

    I got it to work!  Even though I had the same connection setting, for some reason by naming the connection "DefaultConnection" worked.

    I used this connection:

    <add name="DefaultConnection" connectionString="Data Source=myLocations.db.999999.hostedresource.com;
    Initial Catalog=myLocations; User ID=myLocations; Password='your password';"providerName="System.Data.SqlClient" />

    For more reference, see this article: http://httpjunkie.com/2014/954/using-godaddy-sql-server-w-asp-net-mvc5-code-first/

    Thanks for your help on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 14, 2016 3:39 AM