Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900