473,396 Members | 1,916 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,396 software developers and data experts.

Windows Service - SQLConnection\SQLCommand Unresponsive (Novice)

Hello Everyone,

I'm currently writing a simple Windows Service (C#) that pings an ip address and inserts the pingreply result in a SQL table. I'm able to send a ping request and get the reply status but I have yet to figure out how to get the sql insert to work.

The funny thing is, I'm able to ping and insert through a console application but not a Windows Service. I think it might have something to do with my Account information but my interwebz search has come up empty.

The Details:
  • I am logged into my local computer and not a domain (<computername>\<User>)
  • The SQL Database is loaded locally on my machine (localhost\AdventureWorksDW)
  • I log onto the database using 'Windows Authentication' (<computername>\<User> - Password blank)
  • I have tried all different Account types for the service install with same results (LocalSystem, NetworkService, etc.)
The Code ( in OnStart() ):

Expand|Select|Wrap|Line Numbers
  1. string pingstring = string.Format("INSERT INTO <TABLE> (ping_date, ping_status) VALUES (GETDATE(), '{0}'", pingreply.Status.toString());
  2. SqlConnection connection = new SqlConnection("Server=localhost;Database=AdventureWorksDW;Integrated Security=SSPI;"); \\Trusted_Connection=true gives same result
  3. connection.Open();
  4. SqlCommand command = new SqlCommand(pingstring, connection);            
  5. connection.Close(); 
  6.  
I don't receive any errors, just no results in my <TABLE>.

The code will eventually be loaded onto a development server (on a domain) but I'm trying to iron out any kinks before then.

Thank you in advance for any suggestions.
Jan 13 '10 #1

✓ answered by shauncl

Update: I made a mistake in my explanation. I don't receive an error but when I try and start the service after installation, I get the "The services on Local Computer started and stopped..." message. I've tried the 'clear your event logs' step (from the web) but same result.

If I comment out the sqlconnection code, the service will start.

2 3213
Update: I made a mistake in my explanation. I don't receive an error but when I try and start the service after installation, I get the "The services on Local Computer started and stopped..." message. I've tried the 'clear your event logs' step (from the web) but same result.

If I comment out the sqlconnection code, the service will start.
Jan 14 '10 #2
Found the answer: failed to add connection variable to SQLCommand.

Thanks for the help everyone </sarcasm>
Jan 14 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tressa | last post by:
Sorry to be such a novice about this but..... I have a windows service. It contains two separate files. Both have the same namespace name. I need to pass "bDisplay" into the other file. I am...
14
by: Brian Keating EI9FXB | last post by:
I wonder can anyone reccomment a solution to this problem. Let me explain, I've services running on my system, my application receives diagnostic messages from these services, what i want to do...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
2
by: Dmitry Sazonov | last post by:
I'm novice here and I'm sorry for stupid question. We are trying to understand web services architecture, is it better than TIBCO.Randevouz and does webservices fit our needs. I understand, I...
3
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
0
by: artsohc | last post by:
Hey Everyone, this is my first time posting so go easy on me. I am trying to hook up music-on-hold at the office I work at. I got all the music loaded and I got Windows Media Player working while...
10
by: tshad | last post by:
I have a Windows Service that I need to put to sleep for about 10-20 minutes. The problem is that if you try to shut it down during this time, it will tell you that the service didn't respond in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.