473,325 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

use an oledbconnection on more than one form

hcs
Hello,

i have got a form working which displays data from an access database. is it
possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers
Nov 21 '05 #1
6 1232
Yes it is possible to share connections. But do remember that ADO.NET will
pool the connections for you automatically, and in most cases it makes sense
to let ADO.NET pool the connections for you rather than you pooling them
yourself. It could be argued that for a winforms app connection pooling is
uneccessary but I digress especially because by not connection pooling you
lock yourself in a bad architecture that prevents you from remtoing part of
your application to an app server and sharing connections in a database
layer over there as the demands of your application continue to grow.

Even if you were to pool the *instance* of the connection object, you'd only
be pooling the instance, not the underlying connections (which is what you
really want to do). To do that you'd have to explicitly disable connection
pooling.

Now if you still insist on sharing connections, you'd have to expose the
connection objects from this form as public variables and let the other form
access them via an instance of this form. If it is an MDI application or
similar, it may make sense to keep these connections as the logical
equivalence of global variables on the main parent form and pass the
references to the child forms.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is it possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers

Nov 21 '05 #2
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure
that you close all those bad boys once their opened so they are returned to
the pool

In VB you can create the datasets- adapters etc as either shared properties
or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is it possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers

Nov 21 '05 #3
hcs
Thanks you have helped point me in the right direction

"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it possible to share the connections, dataadapter and datasets that have
been setup in this form on another form???

Cheers

Nov 21 '05 #4
KSC
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close
it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure
that you close all those bad boys once their opened so they are returned to
the pool

In VB you can create the datasets- adapters etc as either shared properties
or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is

it
possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers


Nov 21 '05 #5
Remember connection object != actual db connection. Connection object sits
on top of a connection pool.

If you simply create a connection object, that object's state is closed ..
HOWEVER .. there might be one or more open connections in the connection
pool underneath.

If you call a dataadapter.fill, and pass it a connection *object*, it
changes it's state to Open, fills, and Close.

Now, when it calls Open, what happens behind the scenes is - it checks if
there is an available and idle open connection in the connection pool. if
there is, it hands it over, else opens a brand new one. But to your
application, it won't even notice the difference - except in better
performance maybe.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"KSC" <KS*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure that you close all those bad boys once their opened so they are returned to the pool

In VB you can create the datasets- adapters etc as either shared properties or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it
possible to share the connections, dataadapter and datasets that have

been setup in this form on another form???

Cheers


Nov 21 '05 #6
Remember connection object != actual db connection. Connection object sits
on top of a connection pool.

If you simply create a connection object, that object's state is closed ..
HOWEVER .. there might be one or more open connections in the connection
pool underneath.

If you call a dataadapter.fill, and pass it a connection *object*, it
changes it's state to Open, fills, and Close.

Now, when it calls Open, what happens behind the scenes is - it checks if
there is an available and idle open connection in the connection pool. if
there is, it hands it over, else opens a brand new one. But to your
application, it won't even notice the difference - except in better
performance maybe.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"KSC" <KS*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure that you close all those bad boys once their opened so they are returned to the pool

In VB you can create the datasets- adapters etc as either shared properties or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it
possible to share the connections, dataadapter and datasets that have

been setup in this form on another form???

Cheers


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lilly | last post by:
Hi all. I'm really sorry for this post, I'm sure most of you will think it's a silly question, but the following doesn't work and I'm really new to ASP.NET: <%@ Page Language="C#" %> <%@...
1
by: Matthias Kwiedor | last post by:
Hello! My Application is Multi-Threaded, where i have several threads which get datas and write them to the database, or have to read from the database to compare the datas and make updates if...
2
by: Grant | last post by:
My C# web application connects to an Access database using the OleDbConnection and OleDbDataReader. I have 3 other computers that connect to this server but very frequently I get an 'Unspecified...
2
by: Roger Cantillo | last post by:
Hi, I'm using oleDBConnection to connect to SQL server. I keep getting "SQL Server does not exist" on Open event. The code I'm using is the following Dim objConn As New...
1
by: Keith | last post by:
Hi, if have this method in a cs file that connections to a database and returns a datareader to my web form. public OleDbDataReader GetDataReader(string theSQL) { theConn = new...
2
by: dave | last post by:
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...
0
by: Tony Johansson | last post by:
Hello! We have a database and several forms that access the database. When we access the database from all the different forms we only want to have one OleDbConnection that all the forms use. I...
6
by: bokiteam | last post by:
Hi All, I have this error msg, but I have already import lib, could you please advice? Imports System.Data.OleDb Public Class Form1 Inherits System.Windows.Forms.Form Dim cn As...
7
by: Miro | last post by:
I think i have found my problem following an example ive searched for on the net. I am using vb.net 2005 express. What I am looking for is a drag drop from the toolbar that is an...
1
by: Mel | last post by:
I am performing the same recordset multiple times, just passing different parameters each time. Is there a way to do this more efficiently without having to close and re-open the connection and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.