Solved

converting vbs to vb.net

Posted on 2013-11-08
2
318 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

20 Experts available now in Live!

Get 1:1 Help Now