Question

I am using MVC 2and I cannot find a way to change my default connection string in MembershipProvider.

My Web.Config

    <connectionstrings>
       <add name="ConnectionString.SQL Server (SqlClient)" connectionstring="Data     
                  Source=Mysource\testdb-20121109102135.mdf;Initial Catalog=testdb-
                  20121109102135;Integrated Security=True;User Instance=True" 
                  providername="System.Data.SqlClient" />
     </connectionstrings>

Whereas my default connection string generated is

     data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

How can I change it ??

Thank you All

Was it helpful?

Solution

I understand your pain as changing membership provider details can be very vexing .Here all the magic is in Web.config file in the Root folder. All you need to do is add this code to your file after <configuration> .

   <connectionStrings>
<add name="MySqlConnection" connectionString="Data 
  Source=MySqlServer;Initial Catalog=aspnetdb;Integrated
  Security=SSPI;" />

and after <authentication> add

   <authorization>
  <deny users="?"/>
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
  <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" 
         connectionStringName="MySqlConnection" applicationName="MyApplication" 
         enablePasswordRetrieval="false" enablePasswordReset="true" 
         requiresQuestionAndAnswer="true" requiresUniqueEmail="true" 
         passwordFormat="Hashed"/>
  </providers>
</membership>

And Voila! it works.....

For more information please refer Configuring an ASP.NET Application to Use Membership

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top