473,405 Members | 2,445 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,405 software developers and data experts.

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.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!


Aug 11 '06 #1
2 1590
Anyone?

"Rico" <me@you.comwrote in message
news:RI7Dg.367610$iF6.231653@pd7tw2no...
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!




Aug 14 '06 #2
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.
Aug 16 '06 #3

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

Similar topics

6
by: Colleyville Alan | last post by:
I seem to recall reading somewhere that there was a keyword that allowed a variable to have data added to it without losing its contents. a = "Hi " and b = "There" myvar = a myvar = b the...
1
by: sidd | last post by:
Hi all, how do i exit out(unload) of a windows service in case of an error. so i have a code block as follows try { } catch(exception ex) { //log to event log
1
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
4
by: Keith-Earl | last post by:
I have been writing ASP.NET apps since the RTM build and have never seen this. I built a simple app that uses session variables on my DEV laptop. All runs well. I have a simple toggle routine...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
0
by: juhisingh | last post by:
Hi All, I'm creating a windows service thats runs for every one hour. I want to use a variable in that service whose value increments for every one hour the service runs. Say first time when...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
4
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
I've written a .net Windows service in C#. It works most of the time for most people. It is configured to automatically start when Windows boots. Sometimes it fails to start on Windows XP during...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.