Monday, February 20, 2012

mssql server

hello

can anyone tell me if it is possible to use activeX components (com/dcom) in
MS-sql stored procedures?

tiayes it is! Here is an example from a german forum (using Delphi for
programming the com+ object):

Schritt 1: COM+ Objekt (alias ActiveX alias COM-Objekt) in Delphi erzeugen

unit OSSPCOM_Impl;
{$WARN SYMBOL_PLATFORM OFF} interface uses
ActiveX, Mtsobj, Mtx, ComObj, OSSPCOM_TLB, StdVcl; type
TOSSPCOMObj = class(TMtsAutoObject, IOSSPCOMObj)
protected
function Get_Daten: OleVariant; safecall;
procedure DoWork(vInput: OleVariant; out vOutput: OleVariant); safecall;
{ Protected-Deklarationen }
end; implementation uses ComServ; function TOSSPCOMObj.Get_Daten:
OleVariant;
begin
Result := 'Zeichenkette aus dem COM+ Objekt';
SetComplete;
end; procedure TOSSPCOMObj.DoWork(vInput: OleVariant; out vOutput:
OleVariant);
begin
vOutput := vInput + ' (ok)';
SetComplete;
end; initialization
TAutoObjectFactory.Create(ComServer, TOSSPCOMObj, Class_OSSPCOMObj,
ciMultiInstance, tmApartment);
end.

Das kompilierte COM+ Objekt wird danach in eine COM+ Anwendung installiert
(siehe Komponentendienste von Windows 2000/XP/2003).

Schritt 2: Stored Procedure ruft das eigene COM+ Objekt auf

CREATE PROCEDURE spCallCOMplusObj
@.sTXT VARCHAR(50) OUTPUT
AS
Declare @.Object int, @.hr int, @.RetVal int, @.iStatus int
SET @.iStatus = 1
-- Objektinstanz erzeugen
Exec @.hr = sp_OACreate '{0E9447C4-EF22-4570-B202-45D50D3B5EFB}', @.Object
OUTPUT
IF @.hr = 0
BEGIN
SET @.iStatus = 2
END
-- Interface-Methode (Property) abfragen
Exec @.hr = sp_OAGetProperty @.Object, 'Daten', @.sTXT OUTPUT
IF @.hr=0
BEGIN
SET @.iStatus = 3
END
Exec @.hr = sp_OAMethod @.Object, 'DoWork'
IF @.hr=0
BEGIN
SET @.iStatus = 4
END
Exec @.hr = sp_OADestroy @.Object
Return @.iStatus

Schritt 3: Funktion im Query Analyzer des MS SQL Servers testen

DECLARE @.sTEXT VARCHAR(50)
DECLARE @.iResult INT
EXEC @.iResult = spCallCOMplusObj @.sTEXT OUTPUT
SELECT @.iResult,@.sTEXT
Als Ergebnis muss die Zeichenkette aus dem COM+ Objekt sichtbar sein.

hth,
Helmut

"udo polder" <udo@.polder.cd> schrieb im Newsbeitrag
news:bg7l5b$kft$03$1@.news.t-online.com...
> hello
> can anyone tell me if it is possible to use activeX components (com/dcom)
in
> MS-sql stored procedures?
> tia

No comments:

Post a Comment