Sample code for 30+ languages & platforms
SQL Server

Demonstrates how to call AddPfxSourceData for an Email Object

Demonstrates how to call AddPfxSourceData for an Email Object

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @fac int
    EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @fac, 'ReadEntireFile', @pfxBytes OUT, 'qa_data/pfx/some.pfx'

    DECLARE @email int
    EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT

    EXEC sp_OAMethod @email, 'AddPfxSourceData', @success OUT, @pfxBytes, 'PFX_PASSWORD'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @fac
        EXEC @hr = sp_OADestroy @email
        RETURN
      END


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @fac
    EXEC @hr = sp_OADestroy @email


END
GO