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

Create a Wi-Fi QR Code

See more QR Code Examples

Demonstrates a QR code that joins a phone to a Wi-Fi network when scanned. A QR code only holds text. Phones recognize text of the form WIFI:T:;S:;P:;; and offer to join the network. T is WPA (also used for WPA2 and WPA3), WEP, or nopass for an open network, and H:true can be added for a hidden network. In the name and the password, the characters backslash, semicolon, comma, colon and double quote must each be preceded by a backslash.

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', 'WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;'

    --  Level Q, so that the code still scans when it is printed small or gets worn.
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'encoding.qr.errorCorrection', 'Q'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSize', 8

    --  Say which network it is under the code.
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'render.text.enabled', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'render.text.value', 'Wi-Fi: Chilkat Guest'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.text.scale', 2

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_wifi.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 @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END


    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].path'
    PRINT 'file: ' + @sTmp0

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

    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_wifi.png:

    --  image

    --  Sample output:

    --  file: qa_output/qr_wifi.png
    --  QR version: 5
    --  image: 360 x 374 pixels

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


END
GO