Results 1 to 2 of 2

Thread: Question about functions

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Question Question about functions

    Hi, In the code below, I'd like to know if the database connections are closed or not, as the return value is in the datareader loop.

    I now always use the return statement at the end of my functions but would like to know anyway if the connections in the function below get closed.

    Thanks

    Function GetMessageSource(ByVal MessageLocation as String, ByVal MessageID as String) as String
    Try
    Dim objConnection as New OdbcConnection(InstallInfoClass.GetOfficiumConnString())
    Dim sqlGetMessageSource as String
    Dim messageSource as String

    sqlGetMessageSource = "Select MessageSource From MailInbox WHERE InboxMailID = '" & MessageID & "'"

    Dim objCommand as New OdbcCommand(sqlGetMessageSource, objConnection)
    Dim objDataReader as OdbcDataReader
    objConnection.Open
    objDataReader = objCommand.ExecuteReader()

    Do While objDataReader.Read()
    GetMessageSource = Trim(objDataReader("MessageSource").ToString())
    Loop

    objDataReader.Close()
    objConnection.Close()
    Catch objError as Exception
    WriteTest(objError.Description)
    End Try
    End Function

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Declare your SqlConnection WithEvents.

    VB Code:
    1. Friend WithEvents sqlConn As System.Data.SqlClient.SqlConnection

    Then in its StateChange event,

    VB Code:
    1. Private Sub sqlConn_StateChange(ByVal sender As Object, ByVal e As System.Data.StateChangeEventArgs) Handles sqlConn.StateChange
    2.         If e.CurrentState = ConnectionState.Closed Then
    3. '''''''''''''''''''''
    4.  
    5.         End If
    6.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width