Wednesday, April 20, 2011

ASP.NET Configuration Wizard to login with remote sql server

I have been learning ASP.NET by experimenting, watching videos on ASP.NET, and reading forums. I haven't found a quick solution to this though.

Whenever I add the "login" or "createuserwizard" from the toolbox it always adds the new users to a database known as "ASPNETDB.MDF" even if I specify the remote database using a new SqlDataSource.

Is there an easy way to save the login information? Any tutorials that helped you?

From stackoverflow
  • This sounds like you need to Implement a Custom Membership user

  • By default, ASP.NET will use a local file based database to store the login information.

    If you want to use a different database, you need to do a couple of things:

    1. Set up the Remote Database using aspnet_regsql.exe (usually found in C:\Windows\Microsoft.NET\Framework\v2.0.50727) - running this will start it in GUI mode, allowing you select a server and database to add the tables and stored procs to.
    2. Configure your web site to use this database. There are a few of places you need to do this:

    In the ConnectionStrings section of the web.config add your new ConnectionString:

    <add 
      name="zhpCoreContentConnectionString"
      connectionString="Data Source=Hobbiton\SqlExpress;Initial Catalog=zhpCoreContent;Integrated Security=True" 
      providerName="System.Data.SqlClient"/>
    

    In the MembershipProvider section of the web.config, ensure the ConnectionString attribute is set to the same name as your connection string (other settings elided for berevity):

    <membership>
      <providers>
        <add 
          connectionStringName="zhpCoreContentConnectionString"
          applicationName="/doodle"
          name="AspNetSqlMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
    </membership>
    

    If you are using Roles or Profiles you'll want to ensure that they are also using your connectionstring to store everything together, and ensure that the applicationName attribute is common between them.

    Miamian : Thanks for your help. I get the error: The entry 'AspNetSqlMembershipProvider' has already been added.
    Miamian : Ah, once again I do appreciate your help. It enabled me to find this page: http://aspalliance.com/articleViewer.aspx?aId=743&pId=-1 and now I have a remote login.
    Zhaph - Ben Duguid : Glad to hear it :)

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.