Membership/Roles Provider Error

Discussion in 'Site Programming, Development and Design' started by iglesiae, Apr 26, 2011.

  1. Hi!

    I've been publishing my web application for the past few days, and after a lot of problems and errors, it's working perfectly except for this:

    I'm using Visual Studio 2010 to make an ASP.NET MVC Web Aplication...I have an SQL database and an account login mode for administration (only administrators can edit some parts of the web page).
    Therefore, for the account/membership part I used the membership provider that comes with VS...the problem is that I have no idea how to upload crrectly all that information (the already existing accounts, I don't know where VS stores them!), and when I try to log on, I get this 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)

    I know the problem is in the connection string of my web.config file, and probable in some other parts of the same file, but I have no idea what I have to change and to what?!!

    Here's my web.config file:

    <configuration>
    <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
    providerName="System.Data.SqlClient" /> I'M GUESSING THIS IS CAUSING PART OF THE PROBLEM
    <add name="DATABASE1_MDFConnectionString1" connectionString="Data Source=tcp:s04.Winhost.com;Initial Catalog=DB_23268_database1;User ID=DB_23268_database1_user;Password=****;Integrated Security=False"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    <system.web>

    <!-- set code access security trust level - this is generally set in the machine.config -->
    <trust level="Full" originUrl=".*" />

    <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.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
    </compilation>

    <authentication mode="Forms"> THIS IS THE LOGIN PART
    <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership> THIS IS MEMBERSHIP
    <providers>
    <clear/>
    <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> ALSO USES THE SAME CONNECTION STRING
    <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>
    </profile>

    <roleManager enabled="false">
    <providers>
    <clear/>
    <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.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    </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" newVersion="2.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    </configuration>
     
    Last edited by a moderator: Oct 14, 2015
  2. Assuming you have created a MS-SQL db on Winhost through control panel, connect to the db with "Database Explorer" in Visual Studio. Under the properties for the connection, you will see your connection string. It should look something like this:
    <add name="ApplicationServices" connectionString="Data Source=s04.Winhost.com;Initial Catalog=YOURDB;User=YOURUSERNAME;Password=YOURPASSWORD" providerName="System.Data.SqlClient" />

    I think the ASPNET membership provider will write all the necessary tables to the db the first time you create a user.

    Hope this helps
     
    Last edited by a moderator: Oct 14, 2015
  3. Ray

    Ray

    Last edited by a moderator: Oct 14, 2015
  4. ok thanks! i'll do it right now... but I have just one question..if I already have a database for the rst of my application, and it's already uploaded in the server (so that would be the connection string i'll be giving the applicationservice), it won't over write the old database right? because I have a max 1 database plan, so I need to join both databases!! the one i'm already using with the memberships one...is that going to happen??
    and another question, the above link is for asp.net MVC as well right???
    oh and one other question!!!! sorry hahaha... I kind of have two thtreads going on at the same time about the same subject... and in the other one, you (Ray) told me to change the configuration settings on the Package/Publish SQL part of VS, and then build a deployment package, so I already did all that, is that ok??

    thanks!!! I really appreciatte all the help!!!!
     
  5. Ray

    Ray

    Running the aspnet_regsql.exe command should not override anything on your database.
     
  6. PERFECT!!!! the page is working great....thanks Ray for all your help!!!
    if you´re interested, check it out!!!
    www.iglesiaentretodos.org
    bye! thanks
     
  7. Ray

    Ray

    Last edited by a moderator: Oct 14, 2015

Share This Page