![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Transition from MailMan.MxLookupAll to the Chilkat DNS classProvides instructions for replacing deprecated MxLookupAll method calls with the Chilkat Dns class. Note: This example requires Chilkat v11.0.0 or greater.
-- 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) DECLARE @mailman int -- Use "Chilkat_9_5_0.MailMan" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.MailMan', @mailman OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- ... -- ... DECLARE @emailAddr nvarchar(4000) SELECT @emailAddr = 'joe@example.com' -- ------------------------------------------------------------------------ -- The MxLookupAll method is deprecated: DECLARE @sa int EXEC sp_OAMethod @mailman, 'MxLookupAll', @sa OUT, @emailAddr EXEC sp_OAGetProperty @mailman, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @mailman RETURN END -- ... -- ... EXEC @hr = sp_OADestroy @sa -- ------------------------------------------------------------------------ -- Do the equivalent using the Chilkat DNS class DECLARE @dns int -- Use "Chilkat_9_5_0.Dns" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Dns', @dns OUT DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT -- This gets all MX domains for an email address. (Typically one domain.) -- The preferred domain will be at index 0 (see below). DECLARE @success int EXEC sp_OAMethod @dns, 'Query', @success OUT, 'MX', @emailAddr, @json IF @success = 0 BEGIN EXEC sp_OAGetProperty @dns, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @mailman EXEC @hr = sp_OADestroy @dns EXEC @hr = sp_OADestroy @json RETURN END DECLARE @i int SELECT @i = 0 DECLARE @count_i int EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'answer.mx' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i DECLARE @domain nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @domain OUT, 'answer.mx[i].domain' PRINT @domain SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @mailman EXEC @hr = sp_OADestroy @dns EXEC @hr = sp_OADestroy @json END GO |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.