C
csgraham74
Hi guys,
Basically i have been developing in dotnet for a couple of years but
ive had a few issues in regards to error handling.
For example - I have a class that i call passing in a stored procedure
and connection string as a path. My method returns a dataset. In my SP
i have an output parameter which tells me whether the SP select is
successful or not. If i get a error code passed back then i throw an
exception this then returns nothing back to my method call which was
expecting a dataset returned. This then throws an exception on my
webpage - the user therefore does not get the root cause of the error
and it may mislead.
My question is what is the best practice for handling such an error ???
Should i create some type of error handling method that tells the user
on the website that there is a problem and also informs myself as the
developer that there is a problem ???
any help or examples appreciated.
Thanks
CG
***CALLING CODE****** this expects a datset but gets NOTHING if there
is an error
oDS_IncomingReferrals =
obj_SiteFunctions.SQLDSReturn("OADsp_SelectUnassignedReferrals",
libRegistry.cRegistry.GetValue("gcClientAppDataConnection"))
***METHOD***
Public Shared Function SQLDSReturn(ByVal SQLStr As String,
ByVal strRegistry As String) As DataSet
Dim cnstring, str_ReturnValue As String
Dim iConn As New SqlClient.SqlConnection(strRegistry)
Dim iDataAdapter As New SqlClient.SqlDataAdapter
Dim iDataSet As New DataSet
Dim err As String
Dim cmd As New SqlCommand
Try
iConn.Open()
cmd.Connection = iConn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = SQLStr
cmd.Parameters.Add("@Threshhold", SqlDbType.Int)
cmd.Parameters("@Threshhold").Direction =
ParameterDirection.Input
cmd.Parameters("@Threshhold").Value = 0
cmd.Parameters.Add("@Return", SqlDbType.Int)
cmd.Parameters("@Return").Direction =
ParameterDirection.Output
iDataAdapter = New SqlClient.SqlDataAdapter
iDataAdapter = New SqlDataAdapter(cmd)
cmd.ExecuteNonQuery()
iDataAdapter.Fill(iDataSet, "tblRoleReturned")
str_ReturnValue = cmd.Parameters("@Return").Value
If str_ReturnValue <> "0" Then
ErrLabel.Text = "Error Populating dataset"
End If
SQLDSReturn = iDataSet
Catch e As Exception
err = "Unable to connect to reporting database. Please
contact Open + Direct"
End Try
End Function
Basically i have been developing in dotnet for a couple of years but
ive had a few issues in regards to error handling.
For example - I have a class that i call passing in a stored procedure
and connection string as a path. My method returns a dataset. In my SP
i have an output parameter which tells me whether the SP select is
successful or not. If i get a error code passed back then i throw an
exception this then returns nothing back to my method call which was
expecting a dataset returned. This then throws an exception on my
webpage - the user therefore does not get the root cause of the error
and it may mislead.
My question is what is the best practice for handling such an error ???
Should i create some type of error handling method that tells the user
on the website that there is a problem and also informs myself as the
developer that there is a problem ???
any help or examples appreciated.
Thanks
CG
***CALLING CODE****** this expects a datset but gets NOTHING if there
is an error
oDS_IncomingReferrals =
obj_SiteFunctions.SQLDSReturn("OADsp_SelectUnassignedReferrals",
libRegistry.cRegistry.GetValue("gcClientAppDataConnection"))
***METHOD***
Public Shared Function SQLDSReturn(ByVal SQLStr As String,
ByVal strRegistry As String) As DataSet
Dim cnstring, str_ReturnValue As String
Dim iConn As New SqlClient.SqlConnection(strRegistry)
Dim iDataAdapter As New SqlClient.SqlDataAdapter
Dim iDataSet As New DataSet
Dim err As String
Dim cmd As New SqlCommand
Try
iConn.Open()
cmd.Connection = iConn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = SQLStr
cmd.Parameters.Add("@Threshhold", SqlDbType.Int)
cmd.Parameters("@Threshhold").Direction =
ParameterDirection.Input
cmd.Parameters("@Threshhold").Value = 0
cmd.Parameters.Add("@Return", SqlDbType.Int)
cmd.Parameters("@Return").Direction =
ParameterDirection.Output
iDataAdapter = New SqlClient.SqlDataAdapter
iDataAdapter = New SqlDataAdapter(cmd)
cmd.ExecuteNonQuery()
iDataAdapter.Fill(iDataSet, "tblRoleReturned")
str_ReturnValue = cmd.Parameters("@Return").Value
If str_ReturnValue <> "0" Then
ErrLabel.Text = "Error Populating dataset"
End If
SQLDSReturn = iDataSet
Catch e As Exception
err = "Unable to connect to reporting database. Please
contact Open + Direct"
End Try
End Function