Showing posts with label emails. Show all posts
Showing posts with label emails. Show all posts

Friday, March 9, 2012

Dynamically change the sender email address on a SQL2005 Windows 2003 server 64-bit box using da

We currently use xp_smtp_sendmail to send the emails on a sql2000 32-bit box. We are trying to move our databases to a new sql2005 64-bit box. One solution is to replace xp_smtp_sendmail with database mail since xp_smtp_sendmail does not work on 64-bit box. The only problem is that we need to change the sender email dynamically based on the query results and I don't know how to accomplish this by using database mail. Does anyone have an idea? We are not restricted to database-mail solution though.

Thanks for help.

EXECUTE msdb.dbo.sysmail_update_account_sp
@.account_name = 'AdventureWorks Administrator',
@.email_address = 'dba@.Adventure-Works.com'


See SQL Server 2005 Books Online topic:
sysmail_update_account_sp (Transact-SQL)
http://msdn2.microsoft.com/fr-fr/library/ms188381.aspx


EXECUTE msdb.dbo.sysmail_update_account_sp
@.account_name = 'AdventureWorks Administrator',
@.email_address = 'dba@.Adventure-Works.com'

|||Thanks. This answers my question.

Dynamically change the sender email address on a SQL2005 Windows 2003 server 64-bit box using da

We currently use xp_smtp_sendmail to send the emails on a sql2000 32-bit box. We are trying to move our databases to a new sql2005 64-bit box. One solution is to replace xp_smtp_sendmail with database mail since xp_smtp_sendmail does not work on 64-bit box. The only problem is that we need to change the sender email dynamically based on the query results and I don't know how to accomplish this by using database mail. Does anyone have an idea? We are not restricted to database-mail solution though.

Thanks for help.

EXECUTE msdb.dbo.sysmail_update_account_sp
@.account_name = 'AdventureWorks Administrator',
@.email_address = 'dba@.Adventure-Works.com'


See SQL Server 2005 Books Online topic:
sysmail_update_account_sp (Transact-SQL)
http://msdn2.microsoft.com/fr-fr/library/ms188381.aspx


EXECUTE msdb.dbo.sysmail_update_account_sp
@.account_name = 'AdventureWorks Administrator',
@.email_address = 'dba@.Adventure-Works.com'

|||Thanks. This answers my question.

Friday, February 17, 2012

Dynamic SQL Job

I am trying to create a sql job that has multiple steps, emails out the error on a failure, and will continue to the next step. We can not put Outlook on our servers so we can not use SQL Operators.

Basically I would like every step in the job to jump to a failure step that emails out an error message and returns to the step after the step that failed. I could have a failure step for each actual step, but this job has a number of steps and being the anal programmer I am, I don't want to have multiple steps that do the same thing.

I have figured out how to Dynamically update the current sql Job by using sp_update_jobstep and job tokens [STEPID] and [JOBID]. For example the following code will update the job so it will quit job with failure if the step finishes successfully.

declare @.tmpJobID as uniqueidentifier
declare @.tmpStepID as integer

set @.tmpJobID = (convert(uniqueidentifier, [JOBID]))
set @.tmpStepID = [STEPID]

exec sp_update_jobstep @.job_id=@.tmpJobID, @.step_id=@.tmpStepID, @.on_success_action=2

The problem is that the job is not updated until it is completed. So, the changes will not take affect until the next time it is ran. Is there a way to reload the job into memory, or force the job to use the updates?

I have also tried directly updating the sysjobsteps table but that didn't work either.

Thanks much.Well, does anyone know how to get a job to dynamically jump to a specified step?

Thanks much|||Built-in step dependency has limited complexity capabilities. You'll probably haveto merge the steps and...code away!