|
-
Nov 14th, 2004, 01:44 PM
#1
Thread Starter
Hyperactive Member
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
-
Nov 15th, 2004, 12:00 AM
#2
Declare your SqlConnection WithEvents.
VB Code:
Friend WithEvents sqlConn As System.Data.SqlClient.SqlConnection
Then in its StateChange event,
VB Code:
Private Sub sqlConn_StateChange(ByVal sender As Object, ByVal e As System.Data.StateChangeEventArgs) Handles sqlConn.StateChange
If e.CurrentState = ConnectionState.Closed Then
'''''''''''''''''''''
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|