views:

22

answers:

1

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?

+4  A: 

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.

Sruly
There is already the right connectionstring in my web.config. but the ASP.NET configuration tool still tries to connect to the old database. I recognized this after I renamed the old database. The ASP.NET configuration tells me that it could not establish a connection to the database and I need to run aspnet_reqsql tool, but I already tried this to.
stefan.net
The default web.config settings on the server are somehow overriding yours. add a <clear /> to the connection strings and the membership providers
Sruly
Thanks a lot, now I recognized that there is no <membership>-tag in my web.config. How can I generate this? Looks like some kind of strongnamed PublicKeyToken is used. I've only got the connection string in my web.config.
stefan.net
You can copy the code I posted, I copied the code from a working asp.net 3.5 project.
Sruly
Thanks a lot, now I've got a working membership provider. Great!But, my role provider still isn't working. Would you be so kind and post me this entry, too??Thanks in advance!
stefan.net
It's working now completely. I used the same guid for the roleprovider.Thanks one more time!
stefan.net