I want to create windows service which perform CRUD operations using any database such as MS-Sql/MySQL Server for run that service in the background to execute some tasks like Insert, Update and Delete operation on database. I have already created simple Windows Service for Send Mail on particular time interval but right now want to perform CRUD operations using Windows Service and I create one windows service which runs fine ie Service Start Succesfully after installing it but CRUD operations not performing through this service.
code written is -
public void InsertData()
{
string name = "Vijay Patil";
string Address = "Kolhapur";
string Emailid = "Test@gmail.com";
string mbno = "9012345678";
string insert = "USP_UserInfo_Insert";
objconn.cn.Open();
objconn.cmd = new SqlCommand(insert, objconn.cn);
objconn.cmd.CommandType = CommandType.StoredProcedure;
objconn.cmd.Parameters.AddWithValue("@Name", name);
objconn.cmd.Parameters.AddWithValue("@Address_user", Address);
objconn.cmd.Parameters.AddWithValue("@EmailID", Emailid);
objconn.cmd.Parameters.AddWithValue("@Mobilenumber", mbno);
int a = objconn.cmd.ExecuteNonQuery();
if (a > 0)
{
Library.WriteErrorLog("Saved Rec...");
}
}
private void timer1_Tick(object sender, ElapsedEventArgs e)
{
InsertData();
Library.WriteErrorLog("Data Saved successfully");
}
Can any one tell me is it right way to perform CRUD operations using Windows Service ?
Please help me.
It looks like you need to create a webservice. Maybe you should check thoses topics first :
aspnet core : to create a web service using C# with the lastest Microsoft framework
RESTful web services : to perform CRUD operations directly in the url you'll call
Entity framework : to connect your webservice with your sql database
You can start with: https://dzone.com/articles/step-by-step-aspnet-core-restful-web-service-devel
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.