Sample code for 30+ languages & platforms
SQL Server

Create X509PKIPathv1 Containing one Certificate

See more Certificates Examples

Demonstrates how to create a X509PKIPathv1 containing one certificate.

Note: This example requires Chilkat v9.5.0.77 or later.

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
    DECLARE @iTmp0 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 @cert int
    EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- There are many ways to load a certificate -- from a file, from a string or memory, etc.,
    -- and from many different formats.  This example loads the cert from a PEM file.
    -- (LoadFromFile will auto-recognize the format.)
    EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'qa_data/certs/brasil_cert.pem'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @cert
        RETURN
      END

    -- Get the X509PKIPathv1 in base64 format (single line)
    DECLARE @s nvarchar(4000)
    EXEC sp_OAMethod @cert, 'X509PKIPathv1', @s OUT
    EXEC sp_OAGetProperty @cert, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @cert
        RETURN
      END


    PRINT 'X509PKIPathv1: ' + @s

    EXEC @hr = sp_OADestroy @cert


END
GO