Showing posts with label email. Show all posts
Showing posts with label email. Show all posts

Monday, March 26, 2012

Getting Step history info into job notification emails

In SQL Agent, under the properties of a job, there is a notification tab
where you can direct it to send you an email if a job fails. However, that
email appears to contain the history for the overall job, but not the
history detail for the particular step that failed.
For example, the email text I get from my failed job (which has only 1 step)
is:
JOB RUN: 'svCON Check WS02' was run on 10/27/2003 at 10:21:31 AM
DURATION: 0 hours, 0 minutes, 1 seconds
STATUS: Failed
MESSAGES: The job failed. The Job was invoked by User sa. The last step to
run was step 1 (check WS02).
Not very useful. If I right click on the job, choose "View Job History..."
and then check the box for "Show Step Details", then I can click on the row
for Step 1 and see a more precise message:
Executed as user: sa. WS02 workstation did not check in. Last check in was:
Sep 11 2000 7:05AM [SQLSTATE 42000] (Error 50000). The step failed.
Does anyone know how I can add this step history info to the job's email
notification?You can't do it unless you write your own code.
Besides, the purpose of email notification is to let you
know what has failed and then manual intervention by an
operator or dba will be required to fix it.
>--Original Message--
>In SQL Agent, under the properties of a job, there is a
notification tab
>where you can direct it to send you an email if a job
fails. However, that
>email appears to contain the history for the overall job,
but not the
>history detail for the particular step that failed.
>For example, the email text I get from my failed job
(which has only 1 step)
>is:
>JOB RUN: 'svCON Check WS02' was run on 10/27/2003 at
10:21:31 AM
>DURATION: 0 hours, 0 minutes, 1 seconds
>STATUS: Failed
>MESSAGES: The job failed. The Job was invoked by User
sa. The last step to
>run was step 1 (check WS02).
>Not very useful. If I right click on the job,
choose "View Job History..."
>and then check the box for "Show Step Details", then I
can click on the row
>for Step 1 and see a more precise message:
>Executed as user: sa. WS02 workstation did not check in.
Last check in was:
>Sep 11 2000 7:05AM [SQLSTATE 42000] (Error 50000). The
step failed.
>Does anyone know how I can add this step history info to
the job's email
>notification?
>
>.
>

Monday, March 19, 2012

Getting Results in an EMail PDF?

We have the following proc that executes an e-mail and attaches the resulting query as a TXT attachment. Is there a way to make the attachment be a PDF?

@.MYRECIPIENTS varchar (500)

, @.MYSUBJECT varchar (50)

, @.MYBODY varchar (500)

, @.MYQUERY varchar (1000)

, @.MYIMPORTANCE varchar (10)

, @.MYPROFILE varchar (50)

as

declare @.NewSubject varchar(200)

set @.NewSubject = @.MYSUBJECT + ' ' + Cast(GetDate() as varchar(20))

Execute msdb.dbo.sp_send_dbmail

@.profile_name = @.MYPROFILE

,@.recipients = @.MYRECIPIENTS

,@.subject = @.NewSubject

,@.body = @.MYBODY

,@.query = @.MYQUERY

,@.importance = @.MYIMPORTANCE

,@.attach_query_result_as_file = 1

,@.body_format = 'HTML'

Jim,

That's not directly possible. As you recall, SQL Server isn't a printer client, and has no direct capabilities to interact with printers, and PDF is a printer format.

However, you may find some usefulness from a Google? search for a freely available stored procedure that is called "sql 2 pdf".

|||Thanks for the lead. I will follow up on it

Monday, March 12, 2012

Getting OLE DB connection properties in script

I have SSIS packages that send success/failure email upon completion, and I'd like to add a note that identifies the server and database used. I can certainly add variables to the packages and use them when constructing the email, but I'd prefer to get the information directly from the OLE DB connection itself. Is there a way to access the connection string from within a control-flow VB script task? Furthermore, can I get the data source and initial catalog from that connection string, or do I need to parse it myself?

Thanks!

Phil

Yeah you can do that. See here: http://blogs.conchango.com/jamiethomson/archive/2005/10/10/2253.aspx

If you don't want to parse it yourself you could try using the Properties collection using something like the following:

Dts.Connections("Errors").Properties("Format").GetValue(o)

Unfortunately that doesn't actually work cos I don't know what you're supposed to supply to the GetValue() method and the docs are a bit thin. But you can havea go with it if you like.

|||

Thanks, Jamie. You're right - I couldn't make it work with GetValue. However I was able to skin this particular cat thusly:

Dim _dbCxcn As String
Dim _inx As Integer
Dim _dbServer As String
Dim _dbCatalog As String

_dbCxcn = Dts.Connections("My_OLEDB_Connection").ConnectionString
_inx = InStr(_dbCxcn, "Data Source=")
_dbServer = Mid(_dbCxcn, _inx + 12, InStr(_inx, _dbCxcn, ";") - (_inx + 12))
_inx = InStr(_dbCxcn, "Initial Catalog=")
_dbCatalog = Mid(_dbCxcn, _inx + 16, InStr(_inx, _dbCxcn, ";") - (_inx + 16))

Then I constructed the email message using the _dbServer and _dbCatalog variables.

Thanks again!

Phil

Friday, February 24, 2012

getting exclamation sign in message when sent using sql email

i am getting '!' sign in email message when i am sending email using sql
cdo. Is this sql cdo bug or microsoft outlook (email reader bug)Wild guess :: Text encoding might be the culprit.
Best Regards
Vadivel
http://vadivel.blogspot.com
"Vikram" wrote:

> i am getting '!' sign in email message when i am sending email using sql
> cdo. Is this sql cdo bug or microsoft outlook (email reader bug)
>
>|||No its even coming after using textbody, its coming exactly after 989
characters
"Vadivel" <Vadivel@.discussions.microsoft.com> wrote in message
news:F81D2C40-FE28-4D71-8372-AD80085031AC@.microsoft.com...
> Wild guess :: Text encoding might be the culprit.
> Best Regards
> Vadivel
> http://vadivel.blogspot.com
>
> "Vikram" wrote:
>