Solved

converting vbs to vb.net

Posted on 2013-11-08
2
317 Views
Last Modified: 2013-11-12
I need to convert the following vbs code that is currently used as  ActiveX  Script in SSIS package  to vb.net to use in SSIS package as Script Task.

It runs fine on SQL server 2005 but on SQL server 2008 I get the following error:

Error:user script threw an exception" "An error occured while adding the managed SSIS type library to the script host. Verify that the DTS 2000 runtime is installed."

So to get it run on SQL server 2008,  I need to convert it to VB.NET to rewrite it as script Task instead of ActiveX  script.

Thank you.


'**  Script Name..: xCheckForRecordsDTS.vbs 
'**                                           
'*********************************************************************** 

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=myserver;Database=mydatabase;Uid=test;Pwd=test1;"
    
  '** 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

  '** Close object handle 
  oConn.Close 
End Function 

Open in new window

0
Comment
Question by:ocdc
2 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39635632
you should really use a SQL topic because SSIS really is SQL and you don't always need .Net to achieve what you want
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39636109
Hi,
just a dumb question, but your ActiveX script just executes a SQL command to check the result.
Why don`t you use a "Execute SQL Task" in your control flow and then raising the error if no result / number == 0 ?

Thanks.
Rainer
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

19 Experts available now in Live!

Get 1:1 Help Now