Windows Service losing variable value?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rico

    #1

    Windows Service losing variable value?

    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.Command Text = SQL
    SqlComm.Connect ion = Tag_Connection
    da.SelectComman d = SqlComm
    da.Fill(DS)
    GenericDS = DS

    Catch

    iCount = iCount + 1

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

    End Try

    End Function



    Any help would be great.


    Thanks!








  • Rico

    #2
    Re: Windows Service losing variable value?

    Anyone?

    "Rico" <me@you.comwrot e in message
    news:RI7Dg.3676 10$iF6.231653@p d7tw2no...
    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.Command Text = SQL
    SqlComm.Connect ion = Tag_Connection
    da.SelectComman d = SqlComm
    da.Fill(DS)
    GenericDS = DS
    >
    Catch
    >
    iCount = iCount + 1
    >
    If iCount = 1 Then
    ErrorLog(Err.Nu mber, Err.Description , "GenericDS" , "N/A", False)
    End If
    >
    End Try
    >
    End Function
    >
    >
    >
    Any help would be great.
    >
    >
    Thanks!
    >
    >
    >
    >
    >
    >
    >
    >

    Comment

    • Phill W.

      #3
      Re: Windows Service losing variable value?

      Rico wrote:
      Try
      .. . .
      Catch
      iCount = iCount + 1
      If iCount = 1 Then
      ErrorLog(Err.Nu mber, 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.ToS tring(), ...
      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.

      Comment

      Working...