By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

ActiveX Script using IDispatch

P: n/a
I have a Custom DTS Task for SQL Server and I've got it working fine, except
for when I try to access its properties from an ActiveX script. I have
added a new property called Length and a method called Generate that returns
a string. Whenever I get the object in the ActiveX script, the only
properties and methods I can use are for the CustomTask interface, not the
extended properties I've added. Does anyone know why these properties I've
added are not being made available by the IDispatch?

Scott
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
UPDATE:

Simplified customtask that exhibits the problem:

using System;
using System.Runtime.InteropServices;
using Microsoft.SQLServer.DTSPkg80;
using Microsoft.Win32;
using System.Windows.Forms;

[assembly:ClassInterface(ClassInterfaceType.AutoDua l)]

namespace DTS
{

[Guid("[GUID is created by using GUIDGEN.EXE]"), ComVisible(true)]
[ProgId("DTS.SimpleCustomTask")]
public class SimpleCustomTask : CustomTask
{
private string name;
private string description;
private string message;

public SimpleCustomTask()
{
name = "";
description = "SimpleCustomTask description";
}
public void Execute(object pPackage, object pPackageEvents, object
pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult pTaskResult)
{

//Assume failure at the outset
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Failure;

try
{

Package2 package = (Package2) pPackage;
PackageEvents packageEvents = (PackageEvents) pPackageEvents;
PackageLog packageLog = (PackageLog) pPackageLog;
MessageBox.Show(message);

}

//First catch COM exceptions, and then all other exceptions
catch(System.Runtime.InteropServices.COMException e)
{

Console.WriteLine(e);
}
catch(System.Exception e)
{

Console.WriteLine(e);
}

//Return success
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Success;
}

public string Description
{
get { return this.description; }
set { this.description = value; }
}

public string Name
{
get { return name; }
set { this.name = value; }
}

public string Message
{
get { return this.message; }
set { this.message = value; }
}

public Microsoft.SQLServer.DTSPkg80.Properties Properties
{
get { return null; }
}

[System.Runtime.InteropServices.ComVisible(false)]
override public string ToString()
{
return base.ToString();
}
//Registration function for custom task.
[System.Runtime.InteropServices.ComRegisterFunction Attribute()]
static void RegisterServer(Type t)
{
try
{
const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL
Server\\80\\DTS\\Enumeration\\Tasks";
const string CATID_DTSCustomTask =
"{10020200-EB1C-11CF-AE6E-00AA004A34D5}";
string guid = "{" + t.GUID.ToString() + "}";
guid = guid.ToUpper();

Console.WriteLine("RegisterServer {0}", guid);

RegistryKey root;
RegistryKey rk;
RegistryKey nrk;

// Add COM Category in HKEY_CLASSES_ROOT
root = Registry.ClassesRoot;
rk = root.OpenSubKey("CLSID\\" + guid + "\\Implemented Categories",
true);
nrk = rk.CreateSubKey(CATID_DTSCustomTask);
nrk.Close();
rk.Close();
root.Close();

// Add to DTS Cache in HKEY_CURRENT_USER
root = Registry.CurrentUser;
rk = root.OpenSubKey(TASK_CACHE, true);
nrk = rk.CreateSubKey(guid);
nrk.SetValue("", t.FullName);

nrk.Close();
rk.Close();
root.Close();

SimpleCustomTask ct = new SimpleCustomTask();

root = Registry.ClassesRoot;
rk = root.OpenSubKey("CLSID\\" + guid, true);
rk.SetValue("DTSTaskDescription", ct.description);

nrk.Close();
rk.Close();
root.Close();

}
catch(Exception e)
{
System.Console.WriteLine(e.ToString());
}
}

//Unregistration function for custom task.
[System.Runtime.InteropServices.ComUnregisterFuncti onAttribute()]
static void UnregisterServer(Type t)
{
try
{
const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL
Server\\80\\DTS\\Enumeration\\Tasks";
string guid = "{" + t.GUID.ToString() + "}";
guid = guid.ToUpper();

Console.WriteLine("UnregisterServer {0}", guid);

RegistryKey root;
RegistryKey rk;

// Delete from DTS Cache in HKEY_CURRENT_USER
root = Registry.CurrentUser;
rk = root.OpenSubKey(TASK_CACHE, true);
rk.DeleteSubKey(guid, false);
rk.Close();
root.Close();
}
catch(Exception e)
{
System.Console.WriteLine(e.ToString());
}
}

}
}

The ActiveX Script fails on the "Message" assigment:

Function Main()
Dim oPackage
Dim oCT
set oPackage = DTSGlobalVariables.Parent
set oCT = oPackage.Tasks("DTSTask_DTS.SimpleCustomTask_1").C ustomTask
oCT.Message = "Hello World"
Main = DTSTransformStat_SkipInsert
End Function

Change the "set oCT" line to "set oCT =
CreateObject("DTS.SimpleCustomTask")" and it works but of course that is
creating the object once for each record which defeats the purpose of having
the task in the first place.

Obviously I'm having a COM interoperability problem. Anyone know how to
fix?

Scott

"Wm. Scott Miller" <Sc**********@spam.killer.wvinsurance.gov> wrote in
message news:uz**************@TK2MSFTNGP11.phx.gbl...
I have a Custom DTS Task for SQL Server and I've got it working fine, except for when I try to access its properties from an ActiveX script. I have
added a new property called Length and a method called Generate that returns a string. Whenever I get the object in the ActiveX script, the only
properties and methods I can use are for the CustomTask interface, not the
extended properties I've added. Does anyone know why these properties I've added are not being made available by the IDispatch?

Scott

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.