Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Dear all
i want to know how to create windows services for backup of sql server database and how to use this service to my win form application .



Thanks in Advance
Posted

With the below code you will be able to access your local service from a win form.
C#
// ADD "using System.ServiceProcess;" after you add the 
// Reference to the System.ServiceProcess in the solution Explorer
using System.ServiceProcess;

ServiceController myService = new ServiceController();    
myService.ServiceName = "ImapiService";

string svcStatus = myService.Status.ToString();

if (svcStatus == "Running")
{
    myService.Stop();
}
else if(svcStatus == "Stopped")
{
    myService.Start();
}
else
{
    myService.Stop();
}

This article may help you to take a backup of sql database with C# code.

How create Backup and Restore database in c# window application[^]

Write code to backup the database in service.

Happy Coding.

[Edit]Code block added[/Edit]
 
Share this answer
 
v2
A service is a service. It does something.
If you put an IPC interface in it you can communicate with it from an application. I suppose you want to add the missing Server Agent feature of SQL Server Express.
For doing the backup itself I suggest you use SMO Backup class[^].
For the IPC you can use WCF, named pipes, MSMQ, or even plain TCP. But if you want to send only a simple message, like "do backup", this one can be also a solution: http://arcanecode.com/2007/05/30/windows-services-in-c-sending-commands-to-your-windows-service-part-7/[^]
 
Share this answer
 
 
Share this answer
 
There is an article for that!!!
stop asking questions what already are articles!!!
 
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