Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows service which runs every 30 seconds. But after installing, I may want it to run every 2mins or 30mins. So I want the service to collect the interval timer (Start time too. I don't really need to set start time but it would be helpful to know) from the SQL server database. I don't want to set it using app.config, but it would be my last option if I didn't get the solution for this.

I know this logically, so i would prefer if you could help me on how to code it.
Any link on this type of project would also be appreciated.

What I have tried:

I know connection string
C#
con = new SqlConnection("server=servername; database=databasename;uid=username; password=password");

What i don't know is how to assign only last updated value to a variable.
For example If I query like this
C#
string sQuery = "Select IntervalTime from Intervals"
It would give all IntervalTime vales in the table. But I want only last inserted value to be assigned.
Posted
Updated 9-May-18 20:37pm
v2

If I understand the question correctly, the problem is in fetching the data from the database. If that's correct, there are quite a few articles with different kinds of examples covering different kinds of situations. For example, have a look at Properly executing database operations[^]. What comes to the connection string, you can store it in app.config or any place it feels reasonable.
 
Share this answer
 
Comments
Member 13714562 10-May-18 2:38am    
I couldn't find the solution from your link. Also, I have updated my question.
Wendelius 10-May-18 3:02am    
Ok, so the problem is fetching the latest value. Try a query like
Select TOP(1) IntervalTime from Intervals ORDER BY IntervalTime DESC
Member 13714562 10-May-18 3:30am    
I think this might work. Will check and see. Thank you.
app.config can have a connection string. You'll need to make a SQL call to get the value you want to use for your timer
 
Share this answer
 
Comments
Member 13714562 10-May-18 1:39am    
Can you show it using code. How to read the interval time in the table and set it to variable?

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