database connection configuration

D

dave

Hello All -

I've got a couple of .NET Windows forms that have associated
OleDbDataAdapters and OleDbConnection. What is the best approach to
implementing a method for configuring the location of the underlying
data source.

I would like to be able to toggle (in code) between Development, Test,
and Production databases. Lets say for example:

dev db: "c:\databases\dev\myDB.mdb"
test db: "s:\databases\test\myDB.mdb"
prod db: "s:\databases\prod\myDB.mdb"

It seems like I need to set the connection's DataSource property prior
to establishing a connection. But if the connection is associated
with the form, how can I configure the connection in code prior to
loading the form?

Thanks!
Dave
 
C

Curly

Read the Microsoft Document "Deploying .NET Applications
Lifecycle Guide". You can download it for free. This
document makes specific recommendations for handling this
sort of thing.

It's been a while since I read it myself but the gist is
this: You create separate config files - one for
development, one for test, and one for production.
Values for specific connection string parameters vary
within the different config files. (Depending on your
app, you might have other things you want to vary between
the environments.)

Your code reads the parameters from whatever config is
currently in the runtime envisonment. You'll want to
read up a little on "AppSettings" elements in
configuration files and the AppSettings collection in the
System.Configuration namespace.

Then, you just make sure the right config files are
present in the different runtime environments. End-
users, obviously, use the production config file, QA
folks use test, etc.

If your using formal configuratrion management, all three
files can be maintained as individual source items. The
article gives guidelines for naming, etc.

It's a worthwhile read for a lot of other issues you may
run into, as well.

Good luck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top