Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode 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
Bounced Email
Box
CAdES
CSR
CSV
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
MS Storage Providers
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
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Revert to Default DNS Nameservers

See more DNS Examples

Demonstrates how to revert back to the default nameservers of the local system where your application is running.

Note: This example requires Chilkat v9.5.0.96 or later.

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)
    -- The only reason you would have to revert back to the local system's default nameservers
    -- is if your application had previously set different nameservers, and you wish to revert back.

    -- When your application starts, the DNS nameservers to be used are the default nameservers
    -- configured on the system where your application is running.

    -- There is one exception: Chilkat defaults to using the public Google nameservers (8.8.8.8 and 8.8.4.4) for
    -- Android applications. Reverting to the default nameservers would revert to the Google nameservers.

    -- However, Chilkat does not query the local system for the default nameservers unless Chilkat needs
    -- to do a DNS lookup and there not yet any DNS nameservers defined.  Thus technically, when your application
    -- starts, there are no default nameservers. They are auto-assigned when first needed.

    -- If your application explicitly defines DNS nameservers, such as by calling AddDefaultnamervers, or AddNameserver
    -- then Chilkat will not automatically auto-assign.

    DECLARE @dns int
    -- Use "Chilkat_9_5_0.Dns" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Dns', @dns OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Here we are explicitly adding the system default nameservers, because technically this application
    -- has not yet done anything that would require a DNS lookup, and thus DNS nameservers are not yet defined.
    -- Your default nameserver is assumed to not support TLS.
    EXEC sp_OAMethod @dns, 'AddDefaultNameservers', NULL

    -- Let's examine our nameservers
    DECLARE @nsCount int
    EXEC sp_OAGetProperty @dns, 'NumNameservers', @nsCount OUT
    DECLARE @i int
    SELECT @i = 0
    WHILE @i < @nsCount
      BEGIN

        EXEC sp_OAMethod @dns, 'GetNameserver', @sTmp0 OUT, @i
        PRINT @i + 1 + ': ' + @sTmp0
        SELECT @i = @i + 1
      END

    -- On my Windows system, the result is a single nameserver at 
    -- 1: 172.16.16.16

    -- ---------------------------------------------------------
    -- We could add additional nameservers, such as Google and Cloudfare
    DECLARE @supportsTls int
    SELECT @supportsTls = 1
    -- Cloudfare
    EXEC sp_OAMethod @dns, 'AddNameserver', NULL, '1.1.1.1', @supportsTls
    -- Google
    EXEC sp_OAMethod @dns, 'AddNameserver', NULL, '8.8.8.8', @supportsTls

    -- See the nameservers now used by Chilkat
    EXEC sp_OAGetProperty @dns, 'NumNameservers', @nsCount OUT
    SELECT @i = 0
    WHILE @i < @nsCount
      BEGIN

        EXEC sp_OAMethod @dns, 'GetNameserver', @sTmp0 OUT, @i
        PRINT @i + 1 + ': ' + @sTmp0
        SELECT @i = @i + 1
      END

    -- Result:
    -- 1: 172.16.16.16
    -- 2: 1.1.1.1
    -- 3: 8.8.8.8

    -- ---------------------------------------------------------
    -- To revert back to the system default nameservers, clear all
    -- then re-add the default.
    EXEC sp_OAMethod @dns, 'RemoveAllNameservers', NULL
    EXEC sp_OAMethod @dns, 'AddDefaultNameservers', NULL

    -- See the nameservers now used by Chilkat
    EXEC sp_OAGetProperty @dns, 'NumNameservers', @nsCount OUT
    SELECT @i = 0
    WHILE @i < @nsCount
      BEGIN

        EXEC sp_OAMethod @dns, 'GetNameserver', @sTmp0 OUT, @i
        PRINT @i + 1 + ': ' + @sTmp0
        SELECT @i = @i + 1
      END

    -- Result:
    -- 1: 172.16.16.16

    EXEC @hr = sp_OADestroy @dns


END
GO

 

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