Solved

Execute TSQL from an activex task in a DTS package

Posted on 2007-04-04
4
360 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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
rboyd56 earned 125 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 125 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 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