Changing connection string at runtime in Enterprise Library

后端 未结 4 579
星月不相逢
星月不相逢 2020-12-16 04:33

Is there a way to change the connection string of a DataBase object in Enterprise Library at runtime? I\'ve found this link but its a little bit outdated (2005)

I\'v

4条回答
  •  太阳男子
    2020-12-16 04:56

    If you take a look at "Enterprise Library Docs - Adding Application Code" it says this:

    "If you know the connection string for the database you want to create, you can bypass the application's configuration information and use a constructor to directly create the Database object. Because the Database class is an abstract base class, you must construct one of its derived types. The derived Database type determines the ADO.NET data provider. For example, the SqlDatabase class uses the SqlClientFactory provider, the SqlCeDatabase class uses the SqlCeProviderFactory provider, and the OracleDatabase class uses the OracleClientFactory provider. It is your responsibility to construct the appropriate type of Database class for the connection string."

    It then goes on to give some examples. This would suggest that you should not be using the DatabaseFactory and you should be creating a new Database class for each of your different connections.

提交回复
热议问题