473,414 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

passing exception messages from a dll to a client

Hi,

I have created a web application. I have a data access dll to interact
with database. I added this dll as a reference to the web application. Now
let's say if I am calling a function in data access and if it throws
exception (like cannot find stored procedure), how do I retrieve that
exception message back in the web form? In the client, I am able to catch the
exception, but the message I am getting is "Object reference not set to an
instance of an object" not "Cannot find stored procedure". How do i retrieve
the exact message?

Thanks,
Sridhar
Mar 31 '06 #1
5 1360
The "object reference not set to an instance of an object" is a valid
exception.

I'm ready to guess there's a bug in the data access layer.

Probably something like:

}
finally
{
dr.Close();
}
but dr is nothing/null so THAT exception is overwriting the sproc not found
one. The solution is to fix your code :)

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
Hi,

I have created a web application. I have a data access dll to interact
with database. I added this dll as a reference to the web application. Now
let's say if I am calling a function in data access and if it throws
exception (like cannot find stored procedure), how do I retrieve that
exception message back in the web form? In the client, I am able to catch
the
exception, but the message I am getting is "Object reference not set to an
instance of an object" not "Cannot find stored procedure". How do i
retrieve
the exact message?

Thanks,
Sridhar

Mar 31 '06 #2
Hi,

Thanks for the reply. I am filling the dataset using the following code

public function getData() as dataset
try
Dim ds as New dataset
Dim da as New SqlDataAdapter(objSqlCmd)

da.Fill(ds, "test")
catch ex as exception
Dim msg as string = ex.Message
finally

end try
return ds
end function

sub test()
try
Dim ds as dataset
ds = getData()
catch ex as exception
Dim msg as string = ex.message
finally

end try
end sub

If the function getData() is returning nothing, then I am getting the
exception "object reference not set to an instance of an object" since I am
trying to assign nothing to the dataset. How do i fix that?

Thanks,
Sridhar.

"Karl Seguin [MVP]" wrote:
The "object reference not set to an instance of an object" is a valid
exception.

I'm ready to guess there's a bug in the data access layer.

Probably something like:

}
finally
{
dr.Close();
}
but dr is nothing/null so THAT exception is overwriting the sproc not found
one. The solution is to fix your code :)

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
Hi,

I have created a web application. I have a data access dll to interact
with database. I added this dll as a reference to the web application. Now
let's say if I am calling a function in data access and if it throws
exception (like cannot find stored procedure), how do I retrieve that
exception message back in the web form? In the client, I am able to catch
the
exception, but the message I am getting is "Object reference not set to an
instance of an object" not "Cannot find stored procedure". How do i
retrieve
the exact message?

Thanks,
Sridhar


Apr 3 '06 #3
Hi,

Thanks for the reply. I am getting problem when the function returns
"Nothing" and I am trying to assign that Nothing to the variable. Here is the
sample that I am using

Function GetData(pConn as SqlConnection, spName as string, params as
SqlParameter()) as dataset
try
Dim objSqlCmd As SqlCommand
Dim objSqlAdapter As SqlDataAdapter
Dim objDataSet As DataSet
Dim objSqlParam As SqlParameter
Dim strError As String
Dim paramValues As DataTable
Dim paramRow As DataRow
Dim colName As String
Dim colNum As Integer
Try
'Initialize Variables
objSqlCmd = New SqlCommand(storedProcedureName, pConnection)
objSqlAdapter = New SqlDataAdapter(objSqlCmd)

objSqlCmd.CommandType = CommandType.StoredProcedure

'Create a new table for the Output Parameter Values
paramValues = New DataTable("OutputParamValues")
If Not IsNothing(parameters) Then
If parameters.Length > 0 Then
For i As Integer = 0 To parameters.Length - 1
objSqlParam = New
SqlParameter(parameters(i).ParameterName, parameters(i).SqlDbType,
parameters(i).Size)
'If parameter type is output then add column to the
Output Parameter Table
If parameters(i).Direction =
ParameterDirection.Output Then
objSqlParam.Direction = ParameterDirection.Output
colName =
parameters(i).ParameterName.Replace("@", String.Empty)
paramValues.Columns.Add(colName)
Else
objSqlParam.Value = parameters(i).Value
End If
objSqlCmd.Parameters.Add(objSqlParam)
Next
End If
End If

objDataSet = New DataSet
objSqlAdapter.Fill(objDataSet, "Results")

'Check if the Stored Procedure contains any Output Parameters
'If so, add the output parameters to a table and add this table
to the dataset
If paramValues.Columns.Count > 0 Then
paramRow = paramValues.NewRow
colNum = 0
For i As Integer = 0 To objSqlCmd.Parameters.Count - 1
If objSqlCmd.Parameters(i).Direction =
ParameterDirection.Output Then
paramRow(colNum) = objSqlCmd.Parameters(i).Value
colNum = colNum + 1
End If
Next
paramValues.Rows.Add(paramRow)
objDataSet.Tables.Add(paramValues)
End If

Catch ex As Exception
strError = CreateExceptionEmailMessage(ex.Source, ex.Message)
Logger.LogException(ex.Source, ex.Message, ex.StackTrace)
StatusEmailer.SendException(ExceptionEmail, strError)
Throw
Finally
If Not IsNothing(objSqlAdapter) Then
objSqlAdapter.Dispose()
objSqlAdapter = Nothing
End If
If Not IsNothing(objSqlCmd) Then
objSqlCmd.Dispose()
objSqlCmd = Nothing
End If
If Not IsNothing(objSqlParam) Then
objSqlParam = Nothing
End If
End Try
Return objDataSet
end function

sub Test()
objDataSet = GetData(objSqlConn, storedProcedureName, objSqlParams)
'Here I am getting exception since the function is returning nothing and I
am trying to assign Nothing to the variable

end sub
Thanks,
Sridhar

"Karl Seguin [MVP]" wrote:
The "object reference not set to an instance of an object" is a valid
exception.

I'm ready to guess there's a bug in the data access layer.

Probably something like:

}
finally
{
dr.Close();
}
but dr is nothing/null so THAT exception is overwriting the sproc not found
one. The solution is to fix your code :)

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
Hi,

I have created a web application. I have a data access dll to interact
with database. I added this dll as a reference to the web application. Now
let's say if I am calling a function in data access and if it throws
exception (like cannot find stored procedure), how do I retrieve that
exception message back in the web form? In the client, I am able to catch
the
exception, but the message I am getting is "Object reference not set to an
instance of an object" not "Cannot find stored procedure". How do i
retrieve
the exact message?

Thanks,
Sridhar


Apr 3 '06 #4
I don't think the problem is what you think it is. It's completely
valid to set objDataSet = nothing. Therefore, it should be completely
valid to do so on return from a function. Just to be sure, I've tried
in some small samples and never received an exception. What makes you
believe that the error is in this assignment and not happening within
the function itself?

Apr 3 '06 #5
If you didn't swallow exceptions, you'd be a step ahead of the game

Does catching the Exception in getData and setting a message actually HANDLE
it? or does it simply cover it up? Can your code actually continue working
if getData fails? or is it better to call it a lost cause and get a
meanigful error message that you can use to fix your code?

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
Hi,

Thanks for the reply. I am filling the dataset using the following code

public function getData() as dataset
try
Dim ds as New dataset
Dim da as New SqlDataAdapter(objSqlCmd)

da.Fill(ds, "test")
catch ex as exception
Dim msg as string = ex.Message
finally

end try
return ds
end function

sub test()
try
Dim ds as dataset
ds = getData()
catch ex as exception
Dim msg as string = ex.message
finally

end try
end sub

If the function getData() is returning nothing, then I am getting the
exception "object reference not set to an instance of an object" since I
am
trying to assign nothing to the dataset. How do i fix that?

Thanks,
Sridhar.

"Karl Seguin [MVP]" wrote:
The "object reference not set to an instance of an object" is a valid
exception.

I'm ready to guess there's a bug in the data access layer.

Probably something like:

}
finally
{
dr.Close();
}
but dr is nothing/null so THAT exception is overwriting the sproc not
found
one. The solution is to fix your code :)

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
> Hi,
>
> I have created a web application. I have a data access dll to
> interact
> with database. I added this dll as a reference to the web application.
> Now
> let's say if I am calling a function in data access and if it throws
> exception (like cannot find stored procedure), how do I retrieve that
> exception message back in the web form? In the client, I am able to
> catch
> the
> exception, but the message I am getting is "Object reference not set to
> an
> instance of an object" not "Cannot find stored procedure". How do i
> retrieve
> the exact message?
>
> Thanks,
> Sridhar


Apr 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
5
by: zorhel | last post by:
Hi. My clients will be IE, Mozilla and Opera in a Windows and *nix OS. So, my web app need to, from a server, send messages to a specific client (browser), send messages for all clients,...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
1
by: CKane | last post by:
i am trying to build a "missed message" queue on a C# TCP server. many of the devices connecting are mobile and may drop out in bad signal areas. i want to store any messages missed for when they...
1
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
0
by: kencana | last post by:
hi All, I got problem in passing data (more than one) from soap client to the soap server. but if i only passing one data at a time, it works successfully.. The following is the error message i...
0
by: Pieter | last post by:
Hi, When using clickOnce for a VB.NET 2.0 application it installs fine on every computer, except one (a new one...). Every is isstalled, Framework, Mdac, .... The error in the log file is:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.