Hello
Public Function GetFTPInfoSQL() As SqlDataReader
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ftpInfo As SqlDataReader
Try
cmd.Connection = New SqlConnection(ConnString)
cmd.Connection.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = _
"SELECT SystemValue, SystemSetting FROM SystemSettings2 " + _
"WHERE SystemSetting = 'FTPUserName' OR SystemSetting = 'FTPAddress' " + _
"OR SystemSetting = 'FTPPassword' OR SystemSetting = 'FTPRemoteDirectory'"
da.SelectCommand = cmd
ftpInfo = da.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection)------------1
GetFTPInfoSQL = ftpInfo
Return GetFTPInfoSQL
Catch ex As Exception
Dim errorMsg As String
errorMsg = "Error getting FTP Info"
'--- Throw error to DALException class for handling
Throw New DALException(errorMsg, ex)
Finally
'cmd.Connection.Close()---------------------2
da.Dispose()
End Try
End Function
From the above code if i write the cmd.connection.close() i am getting an error as"u cant access when the reader is closed."So i commented it.
Usually we try to dispose or close, connection and objects in Finally block.
So inpite of 1 I wanted 2.If 1 dont gets executed the connection might be open so i attempted to write 2.But its giving an error.
Thanks for any help in advance.
Public Function GetFTPInfoSQL() As SqlDataReader
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ftpInfo As SqlDataReader
Try
cmd.Connection = New SqlConnection(ConnString)
cmd.Connection.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = _
"SELECT SystemValue, SystemSetting FROM SystemSettings2 " + _
"WHERE SystemSetting = 'FTPUserName' OR SystemSetting = 'FTPAddress' " + _
"OR SystemSetting = 'FTPPassword' OR SystemSetting = 'FTPRemoteDirectory'"
da.SelectCommand = cmd
ftpInfo = da.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection)------------1
GetFTPInfoSQL = ftpInfo
Return GetFTPInfoSQL
Catch ex As Exception
Dim errorMsg As String
errorMsg = "Error getting FTP Info"
'--- Throw error to DALException class for handling
Throw New DALException(errorMsg, ex)
Finally
'cmd.Connection.Close()---------------------2
da.Dispose()
End Try
End Function
From the above code if i write the cmd.connection.close() i am getting an error as"u cant access when the reader is closed."So i commented it.
Usually we try to dispose or close, connection and objects in Finally block.
So inpite of 1 I wanted 2.If 1 dont gets executed the connection might be open so i attempted to write 2.But its giving an error.
Thanks for any help in advance.