PC Review


Reply
Thread Tools Rate Thread

connection required - class with new constructor - noobie

 
 
jobs
Guest
Posts: n/a
 
      3rd Feb 2007
I've got a class with a new constructor

Sub New(ByVal connstring As String)
p_cnn = New SqlConnection(connstring)
p_cnn.Open()
End Sub

I instatiate it like this in my ssis script task vb.net code:

Private Const xx As String = "connection string here"
Private Jobs As New JobEngine.Jobs(xx)

Function and methods in the class close the connect at the end
(perhaps part of the problem).

My SSIS code loops and performs select functions multiple times, the
first time it works the second time I get errors that I do not have an
open connection.

What's the best way around this?

- If I don't close my connection at the end of my functions where/ how
do I close it? What happens if I don't close it? during testing I i've
been running the code every few minutes for for hours.

-Any way (without sending my connectiong string every time or hard
coding it my class ) to open and close the connection for the life of
the call to the function?

Thanks for any help or information!

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      3rd Feb 2007
Don't call the .Open method in your constructor. Call it from the method
that does the actual database query or update and close the connection at
the end of that same method.


"jobs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I've got a class with a new constructor
>
> Sub New(ByVal connstring As String)
> p_cnn = New SqlConnection(connstring)
> p_cnn.Open()
> End Sub
>
> I instatiate it like this in my ssis script task vb.net code:
>
> Private Const xx As String = "connection string here"
> Private Jobs As New JobEngine.Jobs(xx)
>
> Function and methods in the class close the connect at the end
> (perhaps part of the problem).
>
> My SSIS code loops and performs select functions multiple times, the
> first time it works the second time I get errors that I do not have an
> open connection.
>
> What's the best way around this?
>
> - If I don't close my connection at the end of my functions where/ how
> do I close it? What happens if I don't close it? during testing I i've
> been running the code every few minutes for for hours.
>
> -Any way (without sending my connectiong string every time or hard
> coding it my class ) to open and close the connection for the life of
> the call to the function?
>
> Thanks for any help or information!
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
InitializeComponent is generating the wrong code for my custom class. Calling it's base class constructor jrhoads23@hotmail.com Microsoft Dot NET Framework Forms 0 1st Feb 2005 07:10 PM
Calling a struct constructor in a class constructor body Karl M Microsoft VC .NET 4 19th Dec 2004 01:21 PM
noobie: copy data in a constructor Christoph Boget Microsoft C# .NET 1 27th Jul 2004 08:00 PM
Initializing base class portion of a derived class in a constructor J.J. Feminella Microsoft C# .NET 2 9th Apr 2004 10:52 PM
Re: Is the lock statement ever required in a static constructor? pokémon Microsoft C# .NET 3 12th Aug 2003 08:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:20 PM.