Jeff Winn
5/31/2008 3:52:00 AM
You must store the configuration for the database in the connection strings
section of the app.config file. There is no way around that with any out of
the box configuration. The configuration section used by the enterprise
library can be omitted - the only thing it stores of any relative value is
the name of the default connection that will be used if no connection string
name is passed to your application.
I've used remoting before to create a seperate appdomain for data access,
which i unload when the configuration needs to change. However, it is rather
complicated to setup. It'd probably be easier to just build your own system
if you must pass the connection string.
"Nicol" <Nicol@discussions.microsoft.com> wrote in message
news:3B775445-E9B6-4F53-ACFE-8BE0248AAA88@microsoft.com...
> Thanks Jeff.
> Now I decided to use Enterprise library 4.0 to support all databases and
> for
> xml support i will add extar coding to my data access layer. And as you
> have
> suggetsed will use only IDataadapter ...etc.,,I have seen enterprise
> library
> by itself for my requirement reads Database connections from confg file..
> I
> ahve requirement to override that and the connection string can be passed
> as
> one of teh argumnet in code.. How can i achieve it from enterprise library
> existing functions... I tried hard in google..NO luck.. can u help me out
> to
> pass connection informations as part of the code itself and use the common
> DB
> Interfaces(IDataReader...) e;lse it should take it from config..
> Thanks in advance
> Nithiya
>
> "Jeff Winn" wrote:
>
>> Well, here's problem with using database specific adapters like
>> SqlDataAdapter and OracleDataAdapter in your application.. what happens
>> when
>> the user changes the database? If you have any database specific adapters
>> being used inside your code, as soon as your application hits it and it's
>> the wrong type of database it's going to break and you probably won't get
>> an
>> error while compiling. It'll just blow up when you run it.
>>
>> You want to stick with base classes or interfaces only that are common
>> between the providers you'll be using. That's why I suggested the
>> IDataReader interface. If you plan on using data adapters you'll probably
>> want to stick with using the IDataAdapter interface.
>>
>> Microsoft.Practices.EnterpriseLibrary.Data.Database is just an abstract
>> type
>> that is used to handles the execution of commands against the connected
>> database. The type of provider defined in your app.config or web.config
>> file
>> determines which type of database the factory will create.
>>
>> <connectionStrings>
>> <add name="MyDbConnString" connectionString="....."
>> providerName="System.Data.SqlClient" />
>> </connectionStrings>
>>
>> .I don't know any links off hand, but i'm sure google will give you
>> plenty
>>
>> "Nicol" <Nicol@discussions.microsoft.com> wrote in message
>> news:EBAD8176-9FE1-42B8-A5B2-A074FBBE7984@microsoft.com...
>> > Thanks Jeff for your good expalnation with eg... This gave me an idea
>> > what
>> > i
>> > need..
>> > One more question, so u r saying we should nt use any objects like
>> > oracleadapter/sqldataadapter class to access the Database. we should
>> > select
>> > independednt classes to access Database. Kindly confirm me. and also
>> > will
>> > it
>> > eb possible to do all operations by using independent classes of DB as
>> > u
>> > have
>> > mentioned in below eg.. If possible plz send me some links to view the
>> > example of such kind...
>> > Thanks for your reply.
>> >
>> > "Jeff Winn" wrote:
>> >
>> >> The Enterprise Library will allow you to use different databases as
>> >> long
>> >> as
>> >> you stick with the common objects in your code. I have never used .NET
>> >> to
>> >> query an XML file so that I'm a little unsure about.
>> >>
>> >> As for using it with different databases here are some tips:
>> >>
>> >> Don't use SqlDataReader or other similar objects in your data layer
>> >> when
>> >> querying the databases. Also, I would suggest using stored procedures
>> >> when
>> >> querying data out of your database since SQL syntax may differ from
>> >> server
>> >> to server.
>> >>
>> >> Here's a very simple example how to ensure querying data out of the
>> >> database
>> >> will keep the type of database transparent:
>> >>
>> >> using Microsoft.Practices.EnterpriseLibrary.Data;
>> >> using System;
>> >> using System.Data;
>> >> using System.Data.Common;
>> >>
>> >> Database db = DatabaseFactory.Create(); // You may need to specify the
>> >> name
>> >> of a connection string here if you're using multiples.
>> >> using (DbCommand cmd = db.GetStoredProcedure("MyProcedureName")) {
>> >> cmd.Parameters.Add("@myparam", DbType.Int32, 123);
>> >>
>> >> using (IDataReader reader = db.ExecuteReader(cmd)) {
>> >> while (reader.Read()) {
>> >> // Do what you want with the data retrieved.
>> >> }
>> >> }
>> >> }
>> >>
>> >> Also, if you're looking for a simpler data layer and do not need
>> >> access
>> >> to
>> >> the rest of the functionality provided by the Enterprise Library you
>> >> may
>> >> want to research LINQ to SQL or NHibernate though again, I'm not sure
>> >> if
>> >> either of those can query XML files either.
>> >>
>> >> "Nicol" <Nicol@discussions.microsoft.com> wrote in message
>> >> news:36A88786-83B6-4B5B-9763-8C5700CEE828@microsoft.com...
>> >> > Hi,
>> >> > My application needs to be configurable for sql server, oracle or
>> >> > anyother
>> >> > DB and also xml file. Will enterprise library suitabel for me? or
>> >> > do i
>> >> > need
>> >> > to create custom solution. PLz suggets me.
>> >> > Thanks
>> >>
>>