Search This Blog

Implementing Oracle-ASP.NET-Provider in C #

Below is the process, how I have implemented the Oracle-ASP.NET-Provider within a ASP.NET web-application.

The first step is to install the latest version of the "Oracle Data Provider for .NET" from the oracle site

Then the next step is to create all the tables required for the Oracle-ASP.NET-Provider. For this, simply run the sql query from the file "InstallAllOracleASPNETProviders.sql" located at "C:\app\[the_computer_name]\product\11.2.0\client_4\ASP.NET\SQL" (considering you have accepted the default location for the installation).

1. Web.config

The web.config of the web-application looks like
[' < ' and ' > ' replaced by ' ( ' and ' ) ']
 Connection String
(add name="OraAspNetConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db_ip)(PORT=db_port))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = orcl)));User Id=user_db;Password=password_db;pooling=true;min pool size=9" providerName="Oracle.DataAccess.Client"/)
Membership Settings
(membership defaultProvider="OracleMembershipProvider")
      (providers)
        (clear/)
        (add name="OracleMembershipProvider" type="Oracle.Web.Security.OracleMembershipProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="" enablePasswordRetrieval="false"
           enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true"
           passwordFormat="Hashed" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""  /)
      (/providers)
   (/membership)

Profile Settings
    (profile)
      (providers)
        (clear/)
        (add name="OracleProfileProvider" type="Oracle.Web.Profile.OracleProfileProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="/"/)
      (/providers)
    (/profile)

Role Settings
    (roleManager enabled="true" defaultProvider ="OracleRoleProvider")
      (providers)
        (clear/)
        (add name="OracleRoleProvider" type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="/" /)
        (!--(add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /)--)
      (/providers)
    (/roleManager)



 Here the OracleDataAccess.dll of version 2 is being used. 

2. Creating User

 protected void btnCreateUser_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtUserEmail.Text);
                txtUsername.Text = "User Created Successfully";
            }
            catch (Exception)
            {
             
                throw;
            }
         
        }

3. Creating Role

protected void btnCreateRole_Click(object sender, EventArgs e)
        {
            String roleName = txtRole.Text.Trim();
            try
            {
                if (!Roles.RoleExists(roleName))
                {
                    Roles.CreateRole(roleName);
                    txtRole.Text = "Role Created Successfully. " + txtRole.Text;
                }
                else
                {
                    txtRole.Text = "Role already exists. " + txtRole.Text;
                }
            }
            catch (Exception ex)
            {
                   throw;
            }
        }

4. Assigning Role to User

protected void btnAddRoleToUser_Click(object sender, EventArgs e)
        {
            try
            {
                Roles.AddUserToRole(txtUser.Text,txtRoleToAdd.Text);
                txtRoleToAdd.Text = "Role added";
            }
            catch (Exception)
            {
             
                throw;
            }
        }

5. User Login

protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
                {
                    FormsAuthentication.SetAuthCookie(txtUserName.Text, true);
                    txtUserName.Text = "success";
                }
                else {
                    txtUserName.Text = "fail";
                }
                 
             
            }
            catch (Exception)
            {
             
                throw;
            }
        }


SecurityNegotiationException WCF

Problem Faced:  created a WCF Service and hosted it in IIS. The client application could communicate with the Service iff it's in the same machine else throws SecurityNegotiationException Exception.

Solution:
Disabled the binding security,

Step1: Right click on the web.config in solution explorer, and select "Edit WCF Configuration"
Step 2: In the endpoint with wsHttpBinding, Create Binding configuration.
Step 3: under security tab, select Mode to None under General section.

ORA-01008: not all variables bound

Sometimes this might be because of the Data Access Provider.
I thought i would increase the data access performance in my application, SO, I changed the data-provider to Oracle.DataAccess.Client and the error occurred, could not figure out the exact reason though, but reverted back to System.Data.OracleClient, and everything worked as previous.

TODO: need to figure it out.