Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing ASP.NET Login Database

In my test enviroment I created a Login and used the ASP.NET Configuration in Visual Studio. It worked perfectly. But now after testing I imported an existing database to my sql-server and this database includes existing asp.net login tables(same structure). In my web-application I want to use these imported tables instead of those in my testing database. I already checked the web.config as well as the aspnetreg tool (don't know the exact name :p)

My question: How can I change the database used by my ASP.NET login?

like image 700
stefan.net Avatar asked Mar 20 '26 10:03

stefan.net


1 Answers

you have to overwrite the default application services connection string to have it use your existing deployed DB

in the web.config connection string section change the default connection string

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

to be whatever your connection string is

or if you want to use a different connection string you can change the name of the connection string used in the membership provider settings also in web.config

<membership>
        <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/"/>
        </providers>
    </membership>

Change the name of the connectionStringName to something else

EDIT Role provider code

<roleManager enabled="true">
        <providers>
            <clear/>
            <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </roleManager>

Again you will want to change connectionStringName to your connection string.

like image 61
Sruly Avatar answered Mar 23 '26 00:03

Sruly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!