How to use a same connection in several VB classes ? 
Author Message
 How to use a same connection in several VB classes ?

Could somebody explain me how to implement following situation ?

I have written a VB DLL with several classes.
I call these classes from within an ASP page.

Most of the classes need a database connection.

I can create a database connection in each class.  The problem is that I call several classes from within the same ASP page, so I end up with several open connections at the same time.

To avoid creating multiple connection objects, I want to create only one connection and use it in the different classes.  How can I do that ?
I could create the connection in my ASP page and pass the connection object to the DLL class as a parameter to each method but I don't like this method.

I also tried to define a public connection object in a global module of the DLL.  This also doesn't work because all calls to the DLL all use the same connection then.

Please help me out.  I'm struggling with this problem already for weeks now.

Dave



Fri, 15 Aug 2003 05:52:48 GMT  
 How to use a same connection in several VB classes ?
Hi,

If I were you, I'd design the objects as stateless and put them in
MTS. A DB connection would then be opened and closed upon every call
to a method in one of your objects, but MTS would pool the connections
for you.

Regards,

        /Olof

Quote:
>This is a multi-part message in MIME format.

>------=_NextPart_000_0064_01C09F7D.AD0B9640
>Content-Type: text/plain;
>    charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable

>Could somebody explain me how to implement following situation ?

>I have written a VB DLL with several classes.
>I call these classes from within an ASP page.

>Most of the classes need a database connection.

>I can create a database connection in each class.  The problem is that I =
>call several classes from within the same ASP page, so I end up with =
>several open connections at the same time.

>To avoid creating multiple connection objects, I want to create only one =
>connection and use it in the different classes.  How can I do that ?
>I could create the connection in my ASP page and pass the connection =
>object to the DLL class as a parameter to each method but I don't like =
>this method.

>I also tried to define a public connection object in a global module of =
>the DLL.  This also doesn't work because all calls to the DLL all use =
>the same connection then.

>Please help me out.  I'm struggling with this problem already for weeks =
>now.

>Dave

>------=_NextPart_000_0064_01C09F7D.AD0B9640
>Content-Type: text/html;
>    charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable

><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
><HTML>
><HEAD>

><META content=3Dtext/html;charset=3Diso-8859-1 =
>http-equiv=3DContent-Type>
><META content=3D'"MSHTML 4.72.3612.1706"' name=3DGENERATOR>
></HEAD>
><BODY bgColor=3D#ffffff>
><DIV><FONT size=3D2>Could somebody explain me how to implement following =
>situation=20
>?</FONT></DIV>
><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT size=3D2>I have written a VB DLL with several =
>classes.</FONT></DIV>
><DIV><FONT size=3D2>I call these classes from within an ASP =
>page.</FONT></DIV>
><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT size=3D2>Most of the classes need a database =
>connection.</FONT></DIV>
><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT color=3D#000000 size=3D2>I can create a database connection =
>in each=20
>class.&nbsp; The problem is that I call several classes from within the =
>same ASP=20
>page, so I end up with several open connections at the same =
>time.</FONT></DIV>
><DIV>&nbsp;</DIV>
><DIV><FONT size=3D2>To avoid creating multiple connection objects, I =
>want to=20
>create only one connection and use it in the different classes.&nbsp; =
>How can I=20
>do that ?</FONT></DIV>
><DIV><FONT color=3D#000000 size=3D2>I could create the connection in my =
>ASP page and=20
>pass the connection object to the DLL class as a parameter to =
><U>each</U> method=20
>but I don't like this method.</FONT></DIV>
><DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT color=3D#000000 size=3D2>I also tried to define a public =
>connection=20
>object in a global module of the DLL.&nbsp; This also doesn't work =
>because=20
><U>all</U> calls to the DLL all use the same connection =
>then.</FONT></DIV>
><DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT size=3D2>Please help me out.&nbsp; I'm struggling with this =
>problem=20
>already for weeks now.</FONT></DIV>
><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
><DIV><FONT size=3D2>Dave</FONT></DIV></BODY></HTML>

>------=_NextPart_000_0064_01C09F7D.AD0B9640--

-------------------



Fri, 15 Aug 2003 15:10:24 GMT  
 How to use a same connection in several VB classes ?
hi all.

I'm interested in the thing as well.

At the moment I use a Data Environvent in my project in order to use the db
connection inthe whole project. But I think that your idea is much better.

do you have some information about how to do that?

thanks.


Quote:
> Hi,

> If I were you, I'd design the objects as stateless and put them in
> MTS. A DB connection would then be opened and closed upon every call
> to a method in one of your objects, but MTS would pool the connections
> for you.

> Regards,

> /Olof

> >This is a multi-part message in MIME format.

> >------=_NextPart_000_0064_01C09F7D.AD0B9640
> >Content-Type: text/plain;
> > charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable

> >Could somebody explain me how to implement following situation ?

> >I have written a VB DLL with several classes.
> >I call these classes from within an ASP page.

> >Most of the classes need a database connection.

> >I can create a database connection in each class.  The problem is that I
=
> >call several classes from within the same ASP page, so I end up with =
> >several open connections at the same time.

> >To avoid creating multiple connection objects, I want to create only one
=
> >connection and use it in the different classes.  How can I do that ?
> >I could create the connection in my ASP page and pass the connection =
> >object to the DLL class as a parameter to each method but I don't like =
> >this method.

> >I also tried to define a public connection object in a global module of =
> >the DLL.  This also doesn't work because all calls to the DLL all use =
> >the same connection then.

> >Please help me out.  I'm struggling with this problem already for weeks =
> >now.

> >Dave

> >------=_NextPart_000_0064_01C09F7D.AD0B9640
> >Content-Type: text/html;
> > charset="iso-8859-1"
> >Content-Transfer-Encoding: quoted-printable

> ><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
> ><HTML>
> ><HEAD>

> ><META content=3Dtext/html;charset=3Diso-8859-1 =
> >http-equiv=3DContent-Type>
> ><META content=3D'"MSHTML 4.72.3612.1706"' name=3DGENERATOR>
> ></HEAD>
> ><BODY bgColor=3D#ffffff>
> ><DIV><FONT size=3D2>Could somebody explain me how to implement following
=
> >situation=20
> >?</FONT></DIV>
> ><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT size=3D2>I have written a VB DLL with several =
> >classes.</FONT></DIV>
> ><DIV><FONT size=3D2>I call these classes from within an ASP =
> >page.</FONT></DIV>
> ><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT size=3D2>Most of the classes need a database =
> >connection.</FONT></DIV>
> ><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT color=3D#000000 size=3D2>I can create a database connection =
> >in each=20
> >class.&nbsp; The problem is that I call several classes from within the =
> >same ASP=20
> >page, so I end up with several open connections at the same =
> >time.</FONT></DIV>
> ><DIV>&nbsp;</DIV>
> ><DIV><FONT size=3D2>To avoid creating multiple connection objects, I =
> >want to=20
> >create only one connection and use it in the different classes.&nbsp; =
> >How can I=20
> >do that ?</FONT></DIV>
> ><DIV><FONT color=3D#000000 size=3D2>I could create the connection in my =
> >ASP page and=20
> >pass the connection object to the DLL class as a parameter to =
> ><U>each</U> method=20
> >but I don't like this method.</FONT></DIV>
> ><DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT color=3D#000000 size=3D2>I also tried to define a public =
> >connection=20
> >object in a global module of the DLL.&nbsp; This also doesn't work =
> >because=20
> ><U>all</U> calls to the DLL all use the same connection =
> >then.</FONT></DIV>
> ><DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT size=3D2>Please help me out.&nbsp; I'm struggling with this =
> >problem=20
> >already for weeks now.</FONT></DIV>
> ><DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> ><DIV><FONT size=3D2>Dave</FONT></DIV></BODY></HTML>

> >------=_NextPart_000_0064_01C09F7D.AD0B9640--

> -------------------




Sun, 17 Aug 2003 20:01:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using the same DB connection in several Forms?

2. Using one connection for several ADO Data Controls

3. How can I create a class that exposes several different NewEnum's

4. ? Internet connection sharing, I've seen this posted several times by people

5. ? Internet connection sharing, I've seen this posted several times by people

6. How to add several ADO connections to Crystal Reports

7. ? Internet connection sharing, I've seen this posted several times by people

8. ? Internet connection sharing, I've seen this posted several times by people

9. Passing Classes to other classes (using user defined types)

10. Using Forms in Classes (beginner w/ classes needs help)

11. Using a Class in another Class?

12. Wrapper Class around Class that uses ParamArray

 

 
Powered by phpBB® Forum Software