- You don't know what server the application will be connecting to at runtime.
- You don't know what database the application will be connecting to at runtime.
- You want to be able to provide user logon credentials at runtime.
- In a corporate environment, there are situations where you need to read the connection string from somewhere other than web.config or dataConfiguration.config.
I added a new class called DynamicDatabaseFactory.cs, which takes the server, database, userID and password and creates a new Database object (same as the DatabaseFactory class in the EntLib). In order to support this, the EasyObject class now has the following new properties:
- ConnectionString - set this to a valid connection string (with or without user logon credentials)
- ConnectionServer - The name of the server to connect to
- ConnectionDatabase - The name of the database to connect to
- ConnectionUserID - The UserID to use for login
- ConnectionPassword - The Password for the user
- UseIntegratedSecurity - flag indicating if the dynamic connection should use integrated security.
- DBProviderType - enumeration indicating the provider type, currently only SQL Server and Oracle are supported.
Depending on which properties you set, certain behavior is triggered in the EasyObject.GetDatabase() function. Of course, if you don't set any of these properties, the current behavior of reading from the dataConfiguration file will still work.
Here are the test scenarios that I used:
- Code: Select all
// Scenario #1 : Complete connection string, no integrated security
this.ConnectionString = \"server=127.0.0.1;database=Northwind;User ID=sa;Password=password;Integrated Security=false;\";
// Scenario #2 : Complete connection string, with integrated security
this.ConnectionString = \"server=127.0.0.1;database=Northwind;Integrated Security=true;\";
// Scenario #3 : Partial connection string, no login credentials
this.ConnectionString = \"server=127.0.0.1;database=Northwind;Integrated Security=false;\";
this.ConnectionUserID = \"sa\";
this.ConnectionPassword = \"password\";
// Scenario #4 : No connection string, no integrated security, userID and password specified
this.ConnectionServer = \"127.0.0.1\";
this.ConnectionDatabase = \"Northwind\";
this.ConnectionUserID = \"sa\";
this.ConnectionPassword = \"password\";
// Scenario #5 : No connection string, with integrated security
this.ConnectionServer = \"127.0.0.1\";
this.ConnectionDatabase = \"Northwind\";
this.UseIntegratedSecurity = true;
Comments are welcome. Release is set for tomorr... er, I mean later today!!!
