Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.7.0+

Generate a QR Code as SVG

See more QR Code Examples

Demonstrates SVG output. An SVG is a vector image, so it stays sharp at any size, which suits print and responsive web pages. Setting output.format to svg and output.return to text returns the SVG document as a string in outputs[0].text. The SVG can also be written straight to a file with output.path, the same as a PNG.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @iTmp1 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  This example requires the Chilkat API to have been previously unlocked.
    --  See Global Unlock Sample for sample code.

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.format', 'svg'

    --  An SVG is text, so it can be returned as text rather than as base64.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.return', 'text'

    DECLARE @fmt int
    EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT

    DECLARE @jsonOut int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT

    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END

    DECLARE @sbSvg int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbSvg OUT

    EXEC sp_OAMethod @jsonOut, 'StringOfSb', @success OUT, 'outputs[0].text', @sbSvg


    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].mimeType'
    PRINT 'MIME type: ' + @sTmp0

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'outputs[0].width'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'outputs[0].height'

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].units'
    PRINT 'size: ' + @iTmp0 + ' x ' + @iTmp1 + ' ' + @sTmp0

    EXEC sp_OAGetProperty @sbSvg, 'Length', @iTmp0 OUT

    PRINT 'SVG length: ' + @iTmp0 + ' characters'

    --  The SVG is a complete document that can be saved, or placed inline in an HTML page.
    EXEC sp_OAMethod @sbSvg, 'WriteFile', @success OUT, 'qa_output/qr_chilkat.svg', 'utf-8', 0
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @sbSvg, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        EXEC @hr = sp_OADestroy @sbSvg
        RETURN
      END

    --  The SVG:

    --  image

    --  Sample output:

    --  MIME type: image/svg+xml
    --  size: 148 x 148 px
    --  SVG length: 12500 characters

    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @fmt
    EXEC @hr = sp_OADestroy @jsonOut
    EXEC @hr = sp_OADestroy @sbSvg


END
GO