beginner questions

  • Thread starter Thread starter Tonya
  • Start date Start date
T

Tonya

Hi,

Im new to VB.net and wanted to find out about the best
way to code my connection to my access db.

I wanted to know if it is necessary to place the
connection string and create a new instance of the
olebconnection class on every page that uses a sql
statement.
Is it possible to place this code in a module and then
just use the varible the Conn String is placed in from
all the forms??

What about all the sql statements? can i also code then
in the module and call then whereever the are required in
my application??

Thx for your help
 
'Best' really depends on many things..... like if this app is networked, if
it's a web app or desktop etc.

As far as keeping the connection string in one place like a module, that's
fine. A more flexible way might be to add it into a .config file and then
when the app loads, populate your module or shared property with the
connection string from the .config file. Connection Pooling works different
with a web app vs. the desktop but you will most likely want to take
advantage of the connection pool. As such, open and close them when you are
done with them, dispose of them when the are no longer necessary.

Another thing you really want to consider is where your logic is located.
You can keep all of your data access logic in a few different layers, the
least flexible being the UI layer. As such, you may want to create a
DataAccess layer that and let it get the data and feed the UI with it. It
can call a web service, or fire directly against the DB..there's a lot of
flexibility. If you use this approach, your UI component doesn't even need
to know about the connection string or connections..but your data access
layer could still take advantage of a module or some shared properties.

If you have multiple SQL Statements, but you know what they will be in
advance, you may even want to store those in a Database and load them
dynamically..this would allow you to modify your data queries without ever
recompiling your app. You can load all your SQL in a module as well, or as
shared properties, or in an ArrayList or whatever...it really depends on
your data access strategy.

HTH,

Bill
 
Back
Top