Home All Groups Group Topic Archive Search About

Windows Service losing variable value?

Author
11 Aug 2006 10:41 PM
Rico
Hello,

I wrote a Windows Forms program that works fine using VB.net 2003.  I wrote
the code in stand alone modules, and used the form to call the subs and
functions to make sure everything works fine. The code uses ADO.net to get a
dataset from SQL Server at various points.

Once I completed code and had it as bullet proof as possible, I created a
new Windows Service and ported to the code to this new service.  Although
i'm fairly new to Windows Services, I have the service installed properly,
it works the first time through, but seems to lose the value of a variable
that I had just set.  I keep getting error message 91. Object reference not
set to an instance of an object.

I've been stepping through with the debugger, but can't see any reason why
this occurs, and why it occurs here but not in the Windows Forms project.
The code that seems to break is as follows;

Public Function GenericDS(ByVal SQL As String) As DataSet
Dim SqlComm As New SqlCommand
Dim da As New SqlDataAdapter
Dim DS As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim iCount As Integer

Try

SqlComm.CommandText = SQL
SqlComm.Connection = Tag_Connection
da.SelectCommand = SqlComm
da.Fill(DS)
GenericDS = DS

Catch

iCount = iCount + 1

If iCount = 1 Then
    ErrorLog(Err.Number, Err.Description, "GenericDS", "N/A", False)
End If

End Try

End Function



Any help would be great.


Thanks!

Author
14 Aug 2006 3:55 PM
Rico
Anyone?

"Rico" <m*@you.com> wrote in message
news:RI7Dg.367610$iF6.231653@pd7tw2no...
Show quoteHide quote
> Hello,
>
> I wrote a Windows Forms program that works fine using VB.net 2003.  I
> wrote the code in stand alone modules, and used the form to call the subs
> and functions to make sure everything works fine. The code uses ADO.net to
> get a dataset from SQL Server at various points.
>
> Once I completed code and had it as bullet proof as possible, I created a
> new Windows Service and ported to the code to this new service.  Although
> i'm fairly new to Windows Services, I have the service installed properly,
> it works the first time through, but seems to lose the value of a variable
> that I had just set.  I keep getting error message 91. Object reference
> not set to an instance of an object.
>
> I've been stepping through with the debugger, but can't see any reason why
> this occurs, and why it occurs here but not in the Windows Forms project.
> The code that seems to break is as follows;
>
> Public Function GenericDS(ByVal SQL As String) As DataSet
> Dim SqlComm As New SqlCommand
> Dim da As New SqlDataAdapter
> Dim DS As New DataSet
> Dim dt As DataTable
> Dim dr As DataRow
> Dim iCount As Integer
>
> Try
>
> SqlComm.CommandText = SQL
> SqlComm.Connection = Tag_Connection
> da.SelectCommand = SqlComm
> da.Fill(DS)
> GenericDS = DS
>
> Catch
>
> iCount = iCount + 1
>
> If iCount = 1 Then
>    ErrorLog(Err.Number, Err.Description, "GenericDS", "N/A", False)
> End If
>
> End Try
>
> End Function
>
>
>
> Any help would be great.
>
>
> Thanks!
>
>
>
>
>
>
>
>
Author
16 Aug 2006 3:48 PM
Phill W.
Rico wrote:
> Try
.. . .
> Catch
> iCount = iCount + 1
> If iCount = 1 Then
>     ErrorLog(Err.Number, Err.Description, "GenericDS", "N/A", False)
> End If
>
> End Try

If you're going to use Exceptions, then /use/ them; don't bodge about
with this half-way house.

    Try
       ...
    Catch ex As Exception
       ErrorLog(ex.ToString(), ...
    End Try

I think you'll be surprised at just how much useful stuff there is in
one of those Exception objects ...

HTH,
    Phill  W.