Solved

converting vbs to vb.net

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but it's slow 28 71
How useful is the free version of Selenium? 3 37
I need help converting a bitmap to an image in VB.Net 1 33
Search an image for an image 3 31
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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