Solved

SSIS - Execute SQL task

Posted on 2014-01-14
5
456 Views
Last Modified: 2016-02-10
I have the following script that I am using in Execute SQL Task box in SSIS package but I am getting  an error.(it turns to red color).   Thank you for your help.

Function Main()
  Dim oConn, oRs, oCmd

  '** Create ADO objects
  Set oConn = CreateObject("ADODB.Connection")
  Set oRs = CreateObject("ADODB.Recordset")
  Set oCmd = CreateObject("ADODB.Command")

  '** Set DAO connection properties
  oConn.Open "Driver={SQL Server};Server=test;Database=OCDC;user;Pwd=password;"
   
  '** Set the active connection to the target database ADO Object
  oCmd.ActiveConnection = oConn
'  oCmd.CommandType = adCmdText

  '** Prepare the SQL statement for retrieving a unique task id
  sSQL = "SELECT Count(*) as NumRecords FROM ActiveDirectoryUsers"

  '** Execute the SQL statement and retrieve the data
  Set oRs = oConn.Execute(sSQL)

  '** Move the data set cursor to the first record
  If Not(oRs.EOF and oRs.BOF) Then
    oRs.MoveFirst
  End If

  If oRs.Fields("NumRecords") = 0 Then
    Main = DTSTaskExecResult_Failure
  Else
    Main = DTSTaskExecResult_Success
  End If
0
Comment
Question by:ocdc
5 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39780149
>(it turns to red color).
Define 'it', and post the first error message that appears in the Progress tab when it is executed.

>sSQL = "SELECT Count(*) as NumRecords FROM ActiveDirectoryUsers"
You could also add this in a Data Flow as a source, then have a Row Count after it which reads the row count and sets the return value to a parameter.  Then make all the green arrows after that conditional based on 'IF @row_count == 0'
0
 

Author Comment

by:ocdc
ID: 39780163
>(it turns to red color) means, it doesnt run
0
 

Author Comment

by:ocdc
ID: 39780166
I just need to know what I need to change in the above script to be able to execute it.

P.S. The above script is ActiveX vbs and it doesnt execute  on SQl server 2008 r2 after setting it up as a Job to run.

Thank you.
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39780208
SSIS Execute SQL Task is used to run SQL commands, you supplied a VBScript function.
0
 
LVL 1

Expert Comment

by:kevwit
ID: 39822651
That code won't work in a SQL Task component. You could use it in a Script Component.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Lessons learned during ten years of interviewing for SQL Server Integration Services (SSIS) and other Extract-Transform-Load (ETL) contract roles and two years of staff manager interviewing contractors.
My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now