Monday 15 April 2013

enterprise library - How to set UserID and Password in EnterpriseLibrary 6.0 -


I have coded like this:

# code

DatabaseProviderFactory factory = New DatabaseProviderFactory (); Database = factory Create ("DBinstanceName");

ConfigFile entries

  & lt; OracleConnection Settings & gt; & Lt; Add name = "CNQ" /> & Lt; / OracleConnectionSettings & gt;   

& lt; Connection best & gt; & Lt; Add name = "CNQ" connectionString = "minimum pool size = 0; connection lifetime = 120; maximum pool size = 50; data source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = XXXX .com) (Port = 1521))) (KNECETA = (SID = CNC) (Server = defined)); "PresentName =" Oracle.DataAccess.Client "/> & lt; / ConnectionStrings & gt;

With the above code and configuration settings, the database object is completely created. When I confirm the connection string, it has the value that I The connection was described in the string, so far.

Now, I have to add userID and the password for the connection string on the runtime is no way to add user credentials to the current credential string After creating, the connection string in the database object is read-only.

The only way I know that the configuration file is set in [app.config] We want to do that, because for every user, we have a separate user id and password in the Oracle database.

Actually, I tried the connection object on the command object, and passed the object to the object reader, even then Enterprise Library 6.0, we do not take a connection set in the command object.

How to set user id and password in runtime.

Thanks in advance

To set connection string value on runtime You have to create your database objects programmatically. For example:

  database database = new generic database (gateconnection string), dbprovfirefacturesgatefacturer ("oracle.dat.exe client"));   

Or something like this if you are using OracleDatabase:

  OracleDatabase database = new OracleDatabase (GetConnectionString ());   

You can use expansion methods to hide a small bit of tricks:

  DatabasePrice factory factory = New database provider); Database DB = Factory. Game Connection String (GateConnection String (), DBprovwareFactoryGetFactureri ("Oracle.DataInvest.Customer")); Db = factory.CreateOracleDatabase (GetConnectionString ()); Public Static Class DatabaseProviderFactoryExtensions {Public Static Database CreateWithConnectionString (This DatabaseProviderFactory Factory, String Connection String, DbProviderFactory dbProviderFactory) {New GenericDatabase (Connection String, dbProviderFactory); } Public stable database CreateOracleDatabase (This DatabaseProviderFactory factory, string connection string) {New OracleDatabase (connectionString); }}   

If you know what connection you will get (still on the runtime, but possibly on the application startup), there is another way to reach this issue: DatabaseFactory . SetsDatabases method to return the correct database based on a key Unfortunately, the method only takes one string so that you can not specify a username and password well, but you may be able to do something like that Database: Factor: () = & gt; GetDatabase ("default"), (dbnname) = & gt; gatedabs (dbnnname): ); Database DB = Database Factor. Credits Database (); Public Database GetDatabase (string dbName) {string connectionString = GetConnectionString (dbName); New OracleDatabase return (connectionString); }

Where GetConnectionString method can create a proper connection string based on a name. However, I'm guessing that your description can not be given the best.

No comments:

Post a Comment