Click here to Skip to main content
Rate this: bad
good
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.
 
Regards,
Sharath
Posted 28-Sep-12 21:15pm
Comments
Sandeep Mewara at 29-Sep-12 3:38am
   
You get any error?
Sharath.2.K at 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 at 29-Sep-12 4:03am
   
As Sandeep says, is there an error message? And what connection string are you using, exactly?
Sharath.2.K at 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 at 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 at 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 at 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 at 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 at 1-Oct-12 14:21pm
   
It was an issue with the service account. Thanks...

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 330
1 BillWoodruff 314
2 George Jonsson 274
3 CPallini 265
4 OriginalGriff 257
0 OriginalGriff 5,030
1 CPallini 4,115
2 Sergey Alexandrovich Kryukov 3,554
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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