I've written applications to handle this situation dozens of times over the years. I just want to know if there's a better way.
Here are some examples:
A table contains an expiration date. After that date, I need to make a notification of the expiration (email, messenger, etc).
Someone has not logged in for X days. Need to send a notification.
The way I currently handle it:
Create a table of sent notifications.
Create a view in the database of all expirations/late logins with no record of a notification already sent.
Write a Windows Service to scan the view every X minutes and send the notifications, write them out to the "Sent Notifications" table (which will make it disappear from the view).
Is there any better way of accomplishing this task? I only ask because sometimes some new technology passes me by.
Thanks in advance
I think you could find a possible solution via SSIS (Sql Server Integration Services). You can create a package to monitor the porcess and to send email to those people who need to be informed.
Related
I have a controller that runs and gets data from a database and sends an email through to the client.
This email setting gets set in a form that is saved to a table with the email recipients. I need to run this on a schedule, which the user (client) defines in a form. Here the client can select either weekly, biweekly or monthly.
From here and after this is saved in the database, it is easy enough to pull from the database, but I need a way to run this every time at the time specified by the client (weekly, biweekly, or monthly). I was thinking of using a webjob (Azure) to do this but I am not sure how to approach this.
So
Are there any issues with this approach?
What are some of the other options?
Any recommendations?
Have you taken a look at solutions that are designed for this? Why re-invent the wheel?
Take a look at Hangfire.io
You can then just do the following:
BackgroundJob.Enqueue(BatchClient.Start());
Or you can add a Recurring job:
RecurringJob.AddOrUpdate(() => BatchClient.Start(), Cron.Daily);
There are also other options also worth investigating e.g. Quartz.Net
I don know if this is the best approach out there, but we use this in our company projects (exactly for sending scheduled emails):
We use Cron Expression to define frequency of an action that needs to be perfomed;
We use Quartz.NET to get the next date when this action should be performed;
For the checking the dates and running actions we are using a WCF service, running in a Windows Service on its own thread.
It might be to complex for your need, but it is pretty flexible. You have to decide where and how you store cron expressions and next dates. For the Cron Expression we use the DB next dates we keep in memory.
I need to try to notify a users who are modifying the same page that an update was made to an Excel grid SPA. I was thinking about passing pack and forth the date modified timestamp and if the original is in the past from the current in the database it would mean the grid was updated by someone else. Is there a better way to do this?
Since you've mentioned AJAX, I'll assume this is a web application. This sounds like an excellent candidate for bi-directional communication via websockets. I've used SignalR with great success. It will allow you to publish events from the server to any subscribed clients, allowing you to easily update what they are viewing.
So here's what I'm trying to do.
I'm building an app using c# and MySQL as it's database. The database should basically be able to store inbox, sent mail, drafts, spam and trash typically.
Now here's the issue. This app is supposed to support multiple users. Meaning each user is supposed to see their own email's. Typically this would suggest that I must create a new schema for every new user, anme it accordingly and create tables inside it for inbox, sent, drafts etc.
Yes, it would be possible I suppose but assuming I may have a thousand user's... That's gonna make database management tedious among other issues that may arise.
Question here is would there be a more organised way / method of doing this? Preferably one that would make management or coding for it easier.
Appologies to be so broad. This is for a school project.
This app is supposed to support multiple users.
That basically means you need a table Users and every table supporting multiple users needs a column where you store the Users Primary Key. That way you can have a single table and have the data of multiple users in it.
I am working on a e-commerce website and there is an issue which we are trying to solve.
After customer completed order she is receiving three emails (all of them same) instead of one.
The website is running on three servers and we think that's the problem because using only one server brings one email delivered to the customer.
I would like to know what we should do so the user will receive only one email instead of three and we will still run the website on three servers.
Thanks in advance, Laziale
You cannot count on locking hints in the database for this. A hint is just a hint; there's no guarantee that the locking will happen as you expect (assuming this is SQL Server). In general, a relational database is just that, a database. A table is not a queuing mechanism and you will always have problems if you try to use it that way.
Nonetheless, in order to implement a different solution, we have to determine if a single record is being added to the "queue" or if three records are being added. If it is the first, and only a single record is added but three emails are sent out then the solution is simple. Instead of using a database table as your queue, use Microsoft Message Queues (MSMQ) instead. They are part of Windows Server and have been since at least 2003, maybe even all the way back to 2000. They will provide you with an actual queue specifically designed for what you're trying to accomplish.
If there are three actual records being added to the "queue" table in the database that means there is a code problem. Even with three Web servers in the load balancer, the fact remains that a single order submission only happens on one of those servers. The business logic that places the email notification in the queue could not come from more than one server because the request only originates from one server.
I would check the table first and determine if there are multiple records being added. If not, change the implementation to use MSMQ. If so, check your code to see why more than one record is being added in the request.
I am using MySQL with C# / Visual Studio 2008. I need to know any method so that if one user updates the database, all the logged in users over the network, are notified that a change has been occurred.
If i logged in the database through my application, at that time the serial no of the latest record in the database was 10, and then i someone with the privileges updates the record in the database and at the same time i am being notified that the database has been updated with a new record.
Common example can be of MSN messenger's alert for a friend when he gets online...
Though i really don't want that popup, but alert functionality is something like that...
One more thing to ask:
I want a functionality like if a record's status is not updated (for say about more than 3 hours), then i want all users to get alert about that issue also. This functionality is needed for all of the records, not specifically for new records.
Quite a long answer, but your best bet would be something like SqlCacheDependency.
Also you could use something called the "Reverse AJAX" technique, which is used by Google Mail notifications, and talked about here: How does incoming mail notification on Gmail works?
Besides those two, your own other options AFAIK is simple server polling.
Also, you haven't mentioned what your client is.
Is it a public web site on the internet? Is it an intranet app, it is a WPF app?
If it's a web site, you're best best is client-side callbacks using the Reverse AJAX technique i mentioned.
You probably need to design some kind of poll functionality in your client. For example, you can send a request each minute asking the database "Have you updated anything since [date the client latest got updates]?" If the database answers true, you let the client request the full set of updates. If not, you let it sleep another minute.
Using the SqlDependency Class is a better way to make all your data driven more faster and efficient. It just remove the need of constantly re-query your database checking every time when a changes is made in the data.