connection required - class with new constructor - noobie

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jobs

    #1

    connection required - class with new constructor - noobie

    I've got a class with a new constructor

    Sub New(ByVal connstring As String)
    p_cnn = New SqlConnection(c onnstring)
    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!

  • Scott M.

    #2
    Re: connection required - class with new constructor - noobie

    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" <jobs@webdos.co mwrote in message
    news:1170536766 .735445.133630@ s48g2000cws.goo glegroups.com.. .
    I've got a class with a new constructor
    >
    Sub New(ByVal connstring As String)
    p_cnn = New SqlConnection(c onnstring)
    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!
    >

    Comment

    Working...