I want to do backup of my database on regular basis using windows services.But i am not able to run this service . Below is my code.i was able to successfully installed this service to my local system But when i tried to start it giving me error "The Service xyz.exe started and then stopped.Some Services stopped automatically if they used by other services." when i manually start service from services.msc .I am helpless please if anyone can help me.Below is my code
public static void BackupDatabase(string backUpFile)
{
ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings;
string MyConnectionString = connections["MDASconfig"].ConnectionString;
ServerConnection con = new ServerConnection(MyConnectionString);
Server server = new Server(con);
Backup source = new Backup();
source.Action = BackupActionType.Database;
source.Database = "MDAS";
BackupDeviceItem destination = new BackupDeviceItem(backUpFile, DeviceType.File);
source.Devices.Add(destination);
source.SqlBackup(server);
con.Disconnect();
}
i have already applied some solutions like increase size through Event viewer and started service using same logon account by logon properties of this service.Service is listing in Services.msc but not starting due to above error.