Click here to Skip to main content
12,700,874 members (29,092 online)
Rate this:
Please Sign up or sign in to vote.
Hi All,

I have created a Windows Service in C# .net 3.5. The service establishes connection with SQL server 2005 and execute few stored procedures.
The server where the service is hosted and the database server are remotely located.

The issue is, the service is failing to open the SQL connection. However, using the same connection string, I am able to connect the SQL Server using a Console Application.

I am unable to figure out the issue.

Any resolutions or suggestions would be really very helpful.

Thanks in advance.

Posted 28-Sep-12 22:15pm
Sandeep Mewara 29-Sep-12 3:38am
You get any error?
Sharath.2.K 29-Sep-12 4:08am
object reference not set to an instance, I guess...However, the same works very well for the Console app...Is there any issue related to hosting or so???
OriginalGriff 29-Sep-12 4:03am
As Sandeep says, is there an error message? And what connection string are you using, exactly?
Sharath.2.K 29-Sep-12 4:16am
connections string is something like this : Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
If it is an issue related to connection string, then it might have also caused an issue with the console app, right???
OriginalGriff 29-Sep-12 4:36am
It depends on where you are running the service and the console app from - if they are the same PC, then it should work the same.
If they are different though, you need to establish that the SQL server instance is reachable (and configured as accessible) from both locations. Hence the asking about the connection string. If the address is a local address (Hostname/instancename or local IP address) then it is very likely that the service cannot reach it.
Sharath.2.K 29-Sep-12 4:56am
Both Console and Service are installed on the same server. One more interesting thing is, the same service works fine on the development machine connecting the same SQL server. However on the deployed server, only the console app works and not the Service...
OriginalGriff 29-Sep-12 5:16am
Stupid idea - have you checked permissions? One difference between a console app and a service would be the account it runs under.
Sharath.2.K 29-Sep-12 7:47am
I will definitely check the same and get back if the issue still persist...
Thanks for your time...
Sharath.2.K 1-Oct-12 14:21pm
It was an issue with the service account. Thanks...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100