(SQL Server) Windows Certificate Stores - Find Certificate by Common Name
Searches the Windows certificate stores for a certificate that matches the specified common name (CN).
Note: This example requires Chilkat v10.0.0 or greater.
-- 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 @cert int
-- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @cert, 'LoadByCommonName', @success OUT, 'Chilkat Software, Inc.'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @cert
RETURN
END
EXEC sp_OAGetProperty @cert, 'SubjectDN', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Success.'
EXEC @hr = sp_OADestroy @cert
END
GO
|