Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples
Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Example: Http.CloseAllConnections method

See more HTTP Examples
Demonstrates how to call the CloseAllConnections method.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- 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 @success int
    SELECT @success = 0

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

    -- Demonstrate 
    DECLARE @url nvarchar(4000)
    SELECT @url = 'https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}'

    -- When the request is sent, the {$symbol} is replaced with "MSFT"
    -- and the {$api_key} is replaced with "1234567890ABCDEF"
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'symbol', 'MSFT'
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'api_key', '1234567890ABCDEF'

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

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, @url, @sbJson
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END

    DECLARE @statusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @statusCode OUT
    EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT
    PRINT @sTmp0

    -- The response header contains this:

    -- Date: Tue, 19 Aug 2025 12:18:56 GMT
    -- Content-Type: application/json; charset=utf-8
    -- Transfer-Encoding: chunked
    -- Connection: keep-alive
    -- Content-Encoding: gzip

    -- The "Connection: keep-alive" header ensures the server keeps the connection open for subsequent requests.
    -- If the server responds with a "Connection: close" header, it indicates the connection will be closed after the response. 
    -- Consequently, Chilkat will also close the connection, requiring a new one to be established for any subsequent requests to the same server.

    -- If your application uses the same HTTP object instance to send requests to a different server, a new connection will be established with that server.
    -- Existing connections remain open, with Chilkat maintaining up to 10 open connections. 
    -- If all 10 connections are in use, Chilkat will close the least recently used connection to connect to a new server.

    -- Your application can explicitly close all open connections like this:
    EXEC sp_OAMethod @http, 'CloseAllConnections', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbJson


END
GO

 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.