OleDbConnection DataSource configuration

  • Thread starter Thread starter dave
  • Start date Start date
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
 
Will this work.

If the development and test db's are static can you hard
code them in your source (i.e. as a string array) and have
the production db accessible through a dialog box.

You could test the connection for functionality by
entering relevant connection string data and calling the
open and close methods from within a Try Catch EndTry
Control structure.

ie
Dim DBDiaolg As New OpenFileDialog
If DBDialog.ShowDialog= DialogResult.OK Then
ConnectionString= DBDialog.OpenFile
Dim oleDBConnect As New OleDBConnection(ConnectionString)

Try
oleDBConnect.Open
oleDBConnect.Close 'Or you could leave it open for
subsequent operations
Catch
MsgBox("Incorrect DB")
End Try
End If
OpenForm
 
Hi Dave,

I think you use the drag and drop method from the toolbox with the
dataadapter.

This is a question that is often been in this newsgroup and there have never
been an answer.

It seems that with that method you are sticked with the connection you make
the first time.

Till now is the alternative not using it and do all the work by hand.
(Not that difficult when you know how).

I know it does not help much, but it prevents you thinking that you are
looking for something simple and that you are stupid.

I hope there is someone (maybe you) who corrects me and gives an answer how
to do it with this drag and drop adaptermethod method.

Cor
 
Back
Top