|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Windows Service losing variable value?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! 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! > > > > > > > > Rico wrote:
> Try If you're going to use Exceptions, then /use/ them; don't bodge about .. . . > Catch > iCount = iCount + 1 > If iCount = 1 Then > ErrorLog(Err.Number, Err.Description, "GenericDS", "N/A", False) > End If > > End Try 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.
Can I make my program more efficient ?
Problem with ComboBox My for each loops do not compile - VB 2003 execution from command line Form2.vb[design] innaccessible ! Help! pumping wait primitives - what is that? Run an Access report in a VB .Net application How to detect if program execution is in debug mode? Problem with CustomTyped casting and type checking Binding an Image to a picturebox |
|||||||||||||||||||||||