C
C#•5mo ago
Zee

why is it only my first row of my sql table is being read :(

so I am trying to make this feature where the program checks the sql table every minute and if the due date is 5 minutes before the current date a notification is popped up to the users desktop screen. I am using Tulpep for the notifications, and the windows task scheduler to run the program in the background. now what happens is that the first row is read and thats not all the rows of my sql table. here is what the event viewer shows me when it does the task Log Name: Application Source: TaskReminderService Date: 28/07/2024 21:50:35 Event ID: 0 Task Category: None Level: Information Keywords: Classic User: N/A Computer: Zeeshan Description: Sending notification for task: Watch the new movie , Description: new action film 😄 Event Xml: <Event xmlns="xxxxx"> <System> <Provider Name="TaskReminderService" /> <EventID Qualifiers="0">0</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2024-07-28T20:50:35.1964862Z" /> <EventRecordID>62052</EventRecordID> <Correlation /> <Execution ProcessID="xxxxx" ThreadID="x" /> <Channel>Application</Channel> <Computer>Zeeshan</Computer> <Security /> </System> <EventData> <Data>Sending notification for task: Watch the new movie , Description: new action film :D</Data> </EventData> </Event> as you can see it only reads my first line of my sql table and stops and when the task runs again it still only reads the first line.
No description
9 Replies
Zee
ZeeOP•5mo ago
here is my code how do I get it to check all the tasks maybe something is wrong with my sql search query???
Jimmacle
Jimmacle•5mo ago
can you narrow this code down to the part that makes the sql query that isn't working?
Zee
ZeeOP•5mo ago
// Method to check for due tasks
private void CheckDueTasks()
{
try
{
string connectionString = @"Data Source=D:\Zeeshan\Documents\ToDoListApp\build\Desktop_Qt_6_8_0_MSVC2019_64bit-Debug\database.db";

using (var connection = new SqliteConnection(connectionString))
{
connection.Open();

// SQL query to find tasks that are due
string sql = @"
SELECT TaskName, Description, DueDate, Reminder
FROM UserItems
WHERE (
(Reminder = 'Remind in 24 hrs' AND DueDate <= datetime('now', '+1 day'))
OR (Reminder = 'Remind in a week' AND DueDate <= datetime('now', '+7 day'))
OR (Reminder = 'Remind in a month' AND DueDate <= datetime('now', '+1 month'))
OR (Reminder = 'Never' AND DueDate <= datetime('now'))
OR (DueDate <= datetime('now', '+5 minutes'))
)
";
// Method to check for due tasks
private void CheckDueTasks()
{
try
{
string connectionString = @"Data Source=D:\Zeeshan\Documents\ToDoListApp\build\Desktop_Qt_6_8_0_MSVC2019_64bit-Debug\database.db";

using (var connection = new SqliteConnection(connectionString))
{
connection.Open();

// SQL query to find tasks that are due
string sql = @"
SELECT TaskName, Description, DueDate, Reminder
FROM UserItems
WHERE (
(Reminder = 'Remind in 24 hrs' AND DueDate <= datetime('now', '+1 day'))
OR (Reminder = 'Remind in a week' AND DueDate <= datetime('now', '+7 day'))
OR (Reminder = 'Remind in a month' AND DueDate <= datetime('now', '+1 month'))
OR (Reminder = 'Never' AND DueDate <= datetime('now'))
OR (DueDate <= datetime('now', '+5 minutes'))
)
";
this si the code for checking the sql table
using (var command = new SqliteCommand(sql, connection))
{
using (var reader = command.ExecuteReader())
{
// Process each due task
while (reader.Read())
{
string taskName = reader.GetString(0);
string description = reader.GetString(1);

// Log each task found
EventLog.WriteEntry("TaskReminderService", $"Found task: {taskName}, {description}", EventLogEntryType.Information);

// Send notification
SendNotification(taskName, description);

// Mark task as processed
MarkTaskAsProcessed(taskName, description, connection);
}
}
}
}
}
catch (Exception ex)
{
EventLog.WriteEntry("TaskReminderService", "Error checking due tasks: " + ex.Message, EventLogEntryType.Error);
}
using (var command = new SqliteCommand(sql, connection))
{
using (var reader = command.ExecuteReader())
{
// Process each due task
while (reader.Read())
{
string taskName = reader.GetString(0);
string description = reader.GetString(1);

// Log each task found
EventLog.WriteEntry("TaskReminderService", $"Found task: {taskName}, {description}", EventLogEntryType.Information);

// Send notification
SendNotification(taskName, description);

// Mark task as processed
MarkTaskAsProcessed(taskName, description, connection);
}
}
}
}
}
catch (Exception ex)
{
EventLog.WriteEntry("TaskReminderService", "Error checking due tasks: " + ex.Message, EventLogEntryType.Error);
}
Jimmacle
Jimmacle•5mo ago
so a couple things i would check first 1. run the query in your database management tool and make sure it returns the rows you're expecting 2. step through this code in a debugger to make sure it's not doing something unexpected
Zee
ZeeOP•5mo ago
ok will do thx it returns the expected results so thats good
Jimmacle
Jimmacle•5mo ago
yep, that means the issue is definitely somewhere in the C# code i'd set a breakpoint right before the part that you think is going wrong and step through to watch exactly what it's doing then you can figure out exactly where the issue is
Zee
ZeeOP•5mo ago
I am not too sure which part is going wrong thougj any suggestions of where to start?
Jimmacle
Jimmacle•5mo ago
well, your assumption is that something is going wrong between making the query and reading the results/sending the notifications so if it were me i'd put a breakpoint right before sending the query and stepping through from there
Zee
ZeeOP•5mo ago
ok will try that thanks
Want results from more Discord servers?
Add your server