Change ConnectionString on ASP.NET Membership

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
YZahringer
Posts: 2
Joined: Tue 21 Aug 2012 08:39

Change ConnectionString on ASP.NET Membership

Post by YZahringer » Tue 21 Aug 2012 08:56

Hello,

I would like to change or create the ConnectionString of OracleMembershipProvider at runtime.

How to do that?

Best regards,
Yann

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Change ConnectionString on ASP.NET Membership

Post by Pinturiccio » Wed 22 Aug 2012 13:26

You can change or create the ConnectionString of OracleMembershipProvider at runtime. The following example demonstrates it:

web.config:

Code: Select all

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="hi"
         providerName="Devart.Data.Oracle" />
  </connectionStrings>
...
    <membership defaultProvider="Prov">
      <providers>
        <remove name="Prov" />
        <clear/>
        <add name="Prov" type="OracleMembershipproviderCS.Prov"
             connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>
Default.aspx.cs:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Devart.Data.Oracle.Web.Providers;
using System.Web.Security;

namespace OracleMembershipproviderCS
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Prov.CurrentString = "Your connection string";
            Membership.CreateUser("scott2", "tigerSmart_83Proff");
        }
    }

    public class Prov : OracleMembershipProvider
    {
        public static string CurrentString;

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);
            base.connectionString = CurrentString;
        }
    }
}
You should also run the InstallWebTables.sql script against the database you want to use. The script can be found in the \Program Files\Devart\dotConnect\Oracle\ folder.

Post Reply