The default connection string is in Web.config file.
Sometimes we need to work with more than one database in the same application, so how can we do that?

First, we need to use the SetConnection() method.

SetConnection method is responsible to define the current connection. We will use ConnectionString sentence and the Database Type as parameters for the SetConnection method.

Command.SetConnection({DataBaseType}, {ConnectionString});
  • DataBaseType (Enum): this Enum defines which database type will be set to Command instance. It has the following data types: DataBaseType.Sql, DataBaseType.Oracle, DataBaseType.Oledbc and DataBaseType.OleDb.
  • ConnectionString (String): the connection string sentence.

But, attention!! These changes are permanent. Every command will be executed using this connection.

To recover the old information about the connection we will use the GetDefaultConnectionStrings method and we must set the new parameters (Database Type and ConnectionString) again.

var settings = Command.GetDefaultConnectionSettings();
Command.SetConnection((DataBaseType) Command.GetDataBaseTypeByName(settings.ProviderName), settings.ConnectionString);

That´s it!

Last edited Feb 10, 2009 at 11:11 AM by LucianoLima, version 6

Comments

No comments yet.