[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Execute TSQL from an activex task in a DTS package

Posted on 2007-04-04
4
Medium Priority
?
368 Views
Last Modified: 2008-01-09
I would like to have a dts package email the number of rows in a certain table.  I do not have sa rights to the server so I am using an activex task to send the email.  How can I get the results on the select into a variable in the activex script?

set @sql = 'SELECT @rowcount = COUNT(site_id) FROM gl_schedule WHERE (post_date = CONVERT(DATETIME, ''2007-04-04 00:00:00'', 102))'
0
Comment
Question by:lovingatx
[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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
rboyd56 earned 250 total points
ID: 18853702
If you are using xp_sendmail to send the email there is an @query parameter that you can pass the select statement. This will send the results of the query to the email recepient
0
 

Author Comment

by:lovingatx
ID: 18853742
I can't use xp_sendmail so I am sending the email from an active x task in dts.  I need to get the result of a SQL statement into a variable in the active x task
0
 
LVL 23

Assisted Solution

by:Christopher Kile
Christopher Kile earned 250 total points
ID: 18853783
What database technology are you familiar with in Visual Basic?  Personally, I would recommend ActiveX Data Objects (ADO).  Build a connection and a recordset in ADO just as you would in a script (using CreateObject() to get the objects).  If you need any help with this, please let me know.
0
 

Author Comment

by:lovingatx
ID: 18854337
This problem is resolved.  I added a sql task to the dts package, clicked parameters and defined a global vairable.  I referenced it in the active x script and emailed based on its value as detailed below.

'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************

Function Main()
Dim url
Dim strbody
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim rowcount
Dim strHTML2






'Send email to

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    'ToDo: Enter name or IP address of remote SMTP server.
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.1.1.1"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Update
End With

' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY><B>"
strHTML = strHTML & "TMR warehouse populated with " & DTSGlobalVariables("ROWCOUNT").Value & " rows"
strHTML = strHTML & "</br>"
strHTML = strHTML & "</B></BODY>"
strHTML = strHTML & "</HTML>"

strHTML2 = "<HTML>"
strHTML2 = strHTML2 & "<HEAD>"
strHTML2 = strHTML2 & "<BODY><B>"
strHTML2 = strHTML2 & "TMR warehouse has no data.  will follow up with a future email."
strHTML2 = strHTML2 & "</br>"
strHTML2 = strHTML2 & "</B></BODY>"
strHTML2 = strHTML2 & "</HTML>"

If DTSGlobalVariables("ROWCOUNT").Value = 0 Then
' Apply the settings to the message.
With iMsg
    Set .Configuration = iConf
   
    .To = "recipient"
    .replyto = "recipient@recipient.com"
    .From = "recipient@recipinet.com" 'ToDo: Enter a valid email address.
    .Subject = "FAILURE - TMR Cognos Dashboard Load"
    .HTMLBody = strHTML2
    .Send
End With

Else

' Apply the settings to the message.
With iMsg
    Set .Configuration = iConf
   
    .To = "recipient"
    .replyto = "recipient"
    .From = "recipient" 'ToDo: Enter a valid email address.
    .Subject = "Populated TMR warehouse with data"
    .HTMLBody = strHTML
    .Send
End With

End If


' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
      Main = DTSTaskExecResult_Success
End Function

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

649 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