Sample code for 30+ languages & platforms
SQL Server

DNS Lookup

Do a DNS lookup to resolve a hostname to an IP address.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

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

    DECLARE @maxWaitMs int
    SELECT @maxWaitMs = 10000
    DECLARE @ipAddr nvarchar(4000)
    EXEC sp_OAMethod @socket, 'DnsLookup', @ipAddr OUT, 'www.chilkatsoft.com', @maxWaitMs
    EXEC sp_OAGetProperty @socket, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @socket
        RETURN
      END


    PRINT 'IP Address: ' + @ipAddr

    EXEC @hr = sp_OADestroy @socket


END
GO