connection required - class with new constructor - noobie

  • Thread starter Thread starter jobs
  • Start date Start date
J

jobs

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!
 
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.
 
Back
Top