How to set Userid & Passsword in code in EnterpriseLibrary 6.0

Jun 22, 2013 at 11:43 PM
I have coded like the below:


DatabaseProviderFactory factory = new DatabaseProviderFactory();
database = factory.Create("DBinstanceName");

ConfigFile Entries

<section name="oracleConnectionSettings"    type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings,     Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  requirePermission="true" />
    <add name="CNQ" />
  <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    <add name="CNQ" connectionString=" Min Pool Size=0;Connection Lifetime=120;Max Pool Size=50; Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST= (CONNECT_DATA = (SID = cnq) (SERVER = DEDICATED) ) );"
        providerName="Oracle.DataAccess.Client" />
With the above code and config settings, the DatabaseObject is created perfectly. When I verify the connectionstring it has the values what I had mentioned in the connnection string. So far good.

Now, I have to add the UserId & Password to the connection string at the runtime. There is no methods I could find to add the user credentials to the existing connection string. Becuase, in the Database object the connection string is READ ONLY.

The only way I find is to set in the configuration file[App.config], which is not the way we want, because for every user, we have a separate userid and password in the Oracle database.

In fact, I had tried by settings the connections at the command object, and passed the command object to the execute reader, even then also the enterprise library 6.0, not taking the connection we set in the command object.

Please help us how to set the userid and password in the runtime.

Thanks in advance