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

Create a vCard (Contact) QR Code

See more QR Code Examples

Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.

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.

    --  The second argument of AppendLine is cktrue to end each line with CRLF.
    DECLARE @sbCard int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbCard OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'BEGIN:VCARD', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'VERSION:3.0', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'N:Smith;Alex;;;', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'FN:Alex Smith', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'ORG:Example Company', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'TITLE:Sales Manager', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'TEL;TYPE=CELL:+1-555-0100', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'EMAIL:alex.smith@example.com', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'URL:https://www.example.com', 1
    EXEC sp_OAMethod @sbCard, 'AppendLine', @success OUT, 'END:VCARD', 1

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

    EXEC sp_OAMethod @json, 'UpdateSb', @success OUT, 'payload.text', @sbCard
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSize', 6
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_vcard.png'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'output.overwrite', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.return', 'none'

    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 @sbCard
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END


    EXEC sp_OAGetProperty @sbCard, 'Length', @iTmp0 OUT
    PRINT 'vCard length: ' + @iTmp0

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'QR version: ' + @iTmp0

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].dimensions.modulesWide'

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'symbols[0].dimensions.modulesHigh'
    PRINT 'modules: ' + @iTmp0 + ' x ' + @iTmp1

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

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

    PRINT 'image: ' + @iTmp0 + ' x ' + @iTmp1 + ' pixels'

    --  The image written to qa_output/qr_vcard.png:

    --  image

    --  Sample output:

    --  vCard length: 197
    --  QR version: 10
    --  modules: 57 x 57
    --  image: 390 x 390 pixels

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


END
GO