Windows Service losing variable value?

  • Thread starter Thread starter Rico
  • Start date Start date
R

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!
 
Rico said:
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.
 
Back
Top