By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

connection required - class with new constructor - noobie

P: n/a
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!

Feb 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <jo**@webdos.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
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!

Feb 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.