SQL Server
SQL Server
Get JSON Details from the Last PFX Operation
See more PFX/P12 Examples
Demonstrates Pfx.GetLastJsonData, which replaces the contents of a JsonObject with structured JSON information from the most recent operation.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. The data is copied as a complete replacement and is never merged with existing members. The exact members depend on the operation that produced them.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @pfx int
EXEC @hr = sp_OACreate 'Chilkat.Pfx', @pfx OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The file path is relative to the application's current working directory. An absolute path
-- may also be used. Supply the path appropriate to your own environment.
-- The PFX password should come from a secure source rather than being hard-coded.
DECLARE @password nvarchar(4000)
SELECT @password = 'myPfxPassword'
EXEC sp_OAMethod @pfx, 'LoadPfxFile', @success OUT, 'qa_data/identity.pfx', @password
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @pfx
RETURN
END
-- Copy structured JSON information from the most recent operation into a JsonObject. The contents
-- entirely replace anything already in the object.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @pfx, 'GetLastJsonData', NULL, @json
EXEC sp_OASetProperty @json, 'EmitCompact', 0
DECLARE @jsonStr nvarchar(4000)
EXEC sp_OAMethod @json, 'Emit', @jsonStr OUT
PRINT @jsonStr
-- JSON parsing code for this result can be generated at Chilkat's online tool:
-- https://tools.chilkat.io/jsonParse
EXEC @hr = sp_OADestroy @pfx
EXEC @hr = sp_OADestroy @json
END
GO