Solved

Run task automatically, daily

Posted on 2010-09-14
17
511 Views
Last Modified: 2012-05-10
i would like to run a sql query and other actions automatically and on a daily basis. I need to check the sql database to see if any credit cards are expiring, for example. If so, I need to send an email to that user's email address. I think I can write the code to query the database, but I need to know how to schedule this to run automatically on a daily basis. I do not want to do this manually. I am using VB  and visual web developer 2010 express.

Thank you.
0
Comment
Question by:mlg101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +6
17 Comments
 
LVL 20

Expert Comment

by:wolfcamel
ID: 33679505
write the vb script and make it a task in windows scheduler.
0
 
LVL 1

Author Comment

by:mlg101
ID: 33679524
What is windows scheduler and where do I find it? Is it on the server hosting my website? I have a windows server 2008.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 33679662
SQL Server has all the capabilities to meet your requirements posted above:

>> I would like to run a sql query and other actions automatically and on a daily basis.

Just create a SQL Agent job to run daily

>> I need to check the sql database to see if any credit cards are expiring, for example.

Handle this logic in TSQL scripts and make it a step in your job.

>> If so, I need to send an email to that user's email address. I think I can write the code to query the database, but I need to know how to schedule this to run automatically on a daily basis.

Configure Database mail so that you can easily send email appropriately and include this as a another step of your job..
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 4

Expert Comment

by:senthilkumarsb
ID: 33679673
This you can do it in sql server job it self. Have a look in to below will help you.

http://msdn.microsoft.com/en-us/library/ms191439.aspx
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33679891
If you dont want to do it using SQL Job, you can also create a Windows Service, and using timer control, you can set its time to 24 hours. so it will run daily once a day.

Here you can manage any code level going (if you want to make it on .net code) also you can handle SQL Queries also.
0
 
LVL 3

Expert Comment

by:Deepu Sreedhar
ID: 33680878
I will also go with the Windows Service option, as I did one like this to work in every 24 hrs.
0
 
LVL 1

Expert Comment

by:funazonki
ID: 33681180
You could also consider the windows task scheduler - go to Control Panel - Administrative Tools - start the applet Task Scheduler.

It will schedule pretty much anything you can run at pretty much any frequency you can imagine
0
 
LVL 1

Author Comment

by:mlg101
ID: 33683032
What I would like is just a little bit of an example to get me started in any one of these ideas. I've never done this automatic script thing before and need help.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33683177
0
 
LVL 1

Expert Comment

by:funazonki
ID: 33683189
There are lots of examples here

http://msdn.microsoft.com/en-us/library/aa384006%28v=VS.85%29.aspx 

including sending emails and other stuff - the examples have detailed instructions for registering tasks via a command line app, or there is a GUI interface for the scheduler.
0
 
LVL 1

Author Comment

by:mlg101
ID: 33683911
My version of visual studio does not allow me to create a windows service
0
 
LVL 8

Accepted Solution

by:
Mohit Vijay earned 250 total points
ID: 33684555
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 33687478
>> My version of visual studio does not allow me to create a windows service

Have you tried the approach that can be done in SQL Server which I and some other experts have suggested above..
0
 
LVL 3

Expert Comment

by:xiong8086
ID: 33689767
follow the example step by step if you are using sql server:

http://www.quackit.com/sql_server/tutorial/sql_server_agent_jobs.cfm

and don't forget to start "sql server agent" services.

0
 
LVL 1

Author Comment

by:mlg101
ID: 33693750
rrjegan17 - I made a query in sql server that I got to work in a test window, but when i created a new job in sql server agent, I put that code in the "steps" section and the "command" window. It didn't work there, so I'm not sure how to implement the code in the command area. The code I put there was this as one step:

Declare @Emails varchar(526)
Select @Emails=isnull(@Emails+';','') + a.Email From Student As a
Where a.Email>''
and exists (SELECT * From CreditCard As b WHERE a.StudentID = b.StudentID And b.CCMonth = month(DATEADD("m",-1,GETDATE())) And b.CCYear = DATEPART(year,GETDATE()))

print '@Emails='+ isnull(@Emails, 'empty')

EXEC msdb..sp_send_dbmail @profile_name='MyProfile',
@recipients= @Emails,
@subject='Update billing information',
@body='Hello, your billing information is about to expire. Please update as soon as possible. Thank you.'

And yes, sql server agent is running.
0
 

Expert Comment

by:ed_collen
ID: 33697359
mlq101,

Another suggestion which might save you some time, you can use the at command on windows to schedule tasks quite easily, so if you write the program you could schedule it to run every weekday at 10am using:

at 10:00 /every:M,T,W,Th,F C:\SQL_Email_Program.exe
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 250 total points
ID: 33698857
Try executing this in Job step.
Can you post the error you are obtaining so that it can be fixed accordingly:

Declare @Emails varchar(526);
Select @Emails=isnull(@Emails+';','') + a.Email From Student As a
Where a.Email>''
and exists (SELECT * From CreditCard As b WHERE a.StudentID = b.StudentID And b.CCMonth = month(DATEADD("m",-1,GETDATE())) And b.CCYear = DATEPART(year,GETDATE()));

EXEC msdb..sp_send_dbmail @profile_name='MyProfile',
@recipients= @Emails,
@subject='Update billing information',
@body='Hello, your billing information is about to expire. Please update as soon as possible. Thank you.';
0

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question