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.)
Expand|Select|Wrap|Line Numbers
- string pingstring = string.Format("INSERT INTO <TABLE> (ping_date, ping_status) VALUES (GETDATE(), '{0}'", pingreply.Status.toString());
- SqlConnection connection = new SqlConnection("Server=localhost;Database=AdventureWorksDW;Integrated Security=SSPI;"); \\Trusted_Connection=true gives same result
- connection.Open();
- SqlCommand command = new SqlCommand(pingstring, connection);
- connection.Close();
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.