Can Window Service Call a Stored Procedure?

9pepper

New member
Joined
Feb 22, 2012
Messages
2
Programming Experience
5-10
I used the same lines of codes to call a SQL server store procedure to export sql data to an XML file:
  1. If I call the stored procedure from a window form application, it works and generates the file at the designated location.
  2. If I call the stored procedure from a window service application with a setup project, and the install process run well, and I started the service, and checked the event log, it showed the service start successfully, BUT it FAILED to generate the file at the destination folder. I also run everything as administrator, but it still failed to generate the file. It made me wonder if a window service can call a stored procedure.
Please help.
Because, again, mine ran fine with the window form appl, but window service, I would like to have your sample codes. I have googled around for 3 days now, but could not find the answer. I use vs 2008, sql server 2008, and Windows 7

Thanks!!!!!!!!!!!!!!!!!!!!
 
you set the service to run using an administrator account?

ps; services can call sproc for sure; i've written tens of services that rely on databases
 
I do not know what you meant "set the service to run using an administrator account?", but I have everything, vs2008, sql2008 both run as administrator. I also goto control panel - administrative tools - service - right click and run as administrator. But it does not work. Please help. I also turn of UAC (user access control) on my computer, but does not work either. can you give me a sample of you code.
 
You don't need a code sample. Data access is the same regardless. Just as with any other application, a Windows service must provide appropriate credentials when connecting to the database. If you are using integrated security then the service must be running as a user who has appropriate privileges. What user is the service running as and does that user have permission to connect to the database? Things don't just fail. If the connection fails then you will be getting an error message, provided to help you fix the error. Don;t ignore that information that is provided specifically to help you fix the issue.
 
Back
Top