Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run task automatically, daily

Posted on 2010-09-14
17
Medium Priority
?
512 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
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 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

721 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