SQL Server: Issue with API GET Call Using sp_OA (works Locally, not on SQL Server 2012 Machine)

I’m encountering an issue when making an API GET call on PC with SQL Server 2012 using sp_OACreate with MSXML2.ServerXMLHTTP (also tested with MSXML2.XMLHTTP). The same script works perfectly on my local PC with SQL Server 2019 and receives a response from the API.

This is the code I’m testing:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>DECLARE @URL NVARCHAR(MAX),
@basicAuth NVARCHAR(200),
@Msg NVARCHAR(MAX),
@Object as Int,
@ResponseText as Varchar(8000),
@HTTPStatus int,
@statusText nvarchar(100)
SET @URL = N'https://example.com/api/test'
-- 'MSXML2.XMLHTTP'
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
@URL, 'false'
SET @basicAuth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
SET @basicAuth = 'Basic '+ @basicAuth
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Authorization', @basicAuth
Exec sp_OAMethod @Object, 'send'
EXEC sp_OAGetProperty @Object, 'status', @HTTPStatus OUT
EXEC sp_OAGetProperty @Object, 'statusText', @statusText OUT;
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
Exec sp_OADestroy @Object
PRINT 'Response: '+ ISNULL(@ResponseText, 'NULL')
PRINT 'StatusCode: '+ ISNULL(CAST(@HTTPStatus AS NVARCHAR(100)), 'NULL')
PRINT 'Status: '+ ISNULL(@statusText, 'NULL')
SET @Msg = 'Call Web Api ended. Result: ' + ISNULL(@ResponseText, 'NULL')
PRINT @Msg
</code>
<code>DECLARE @URL NVARCHAR(MAX), @basicAuth NVARCHAR(200), @Msg NVARCHAR(MAX), @Object as Int, @ResponseText as Varchar(8000), @HTTPStatus int, @statusText nvarchar(100) SET @URL = N'https://example.com/api/test' -- 'MSXML2.XMLHTTP' Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT; Exec sp_OAMethod @Object, 'open', NULL, 'get', @URL, 'false' SET @basicAuth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' SET @basicAuth = 'Basic '+ @basicAuth EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Authorization', @basicAuth Exec sp_OAMethod @Object, 'send' EXEC sp_OAGetProperty @Object, 'status', @HTTPStatus OUT EXEC sp_OAGetProperty @Object, 'statusText', @statusText OUT; Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT Exec sp_OADestroy @Object PRINT 'Response: '+ ISNULL(@ResponseText, 'NULL') PRINT 'StatusCode: '+ ISNULL(CAST(@HTTPStatus AS NVARCHAR(100)), 'NULL') PRINT 'Status: '+ ISNULL(@statusText, 'NULL') SET @Msg = 'Call Web Api ended. Result: ' + ISNULL(@ResponseText, 'NULL') PRINT @Msg </code>
DECLARE @URL NVARCHAR(MAX),
    @basicAuth NVARCHAR(200),
    @Msg NVARCHAR(MAX),
    @Object as Int,
    @ResponseText as Varchar(8000),
        @HTTPStatus int, 
    @statusText nvarchar(100)

SET @URL = N'https://example.com/api/test'

-- 'MSXML2.XMLHTTP'
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
        @URL, 'false'

SET @basicAuth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

SET @basicAuth = 'Basic '+ @basicAuth

EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Authorization', @basicAuth

Exec sp_OAMethod @Object, 'send'
EXEC sp_OAGetProperty @Object, 'status', @HTTPStatus OUT
EXEC sp_OAGetProperty @Object, 'statusText', @statusText OUT;
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Exec sp_OADestroy @Object

PRINT 'Response: '+ ISNULL(@ResponseText, 'NULL')
PRINT 'StatusCode: '+ ISNULL(CAST(@HTTPStatus AS NVARCHAR(100)), 'NULL')
PRINT 'Status: '+ ISNULL(@statusText, 'NULL')

SET @Msg = 'Call Web Api ended. Result: ' + ISNULL(@ResponseText, 'NULL')
PRINT @Msg

What could be causing this issue? Are there specific configurations or requirements for MSXML2 on SQL Server 2012 that might be necessary?

Thank you in advance for any suggestions or solutions!

What i’ve tested

  • Working: On my local PC with SQL Server 2019, the script successfully receives a response from the API.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Response: {"result": 1}
StatusCode: 200
Status: OK
Call Web Api ended. Result: {"result": 1}
</code>
<code>Response: {"result": 1} StatusCode: 200 Status: OK Call Web Api ended. Result: {"result": 1} </code>
Response: {"result": 1}
StatusCode: 200
Status: OK
Call Web Api ended. Result: {"result": 1}
  • Not Working on the final PC with SQL Server 2012, where the solution needs to work, the script does not receive any response from the API (Response, StatusCode, and Status are all NULL).
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Response: NULL
StatusCode: NULL
Status: NULL
Call Web Api ended. Result: NULL
</code>
<code>Response: NULL StatusCode: NULL Status: NULL Call Web Api ended. Result: NULL </code>
Response: NULL
StatusCode: NULL
Status: NULL
Call Web Api ended. Result: NULL
  • The PC with the issue can reach the API and get a response using another program, so it is not a network connectivity issue.
  • I also tested on the machine experiencing the issue by executing the SQL script with a different URL (a different server with different IP address) that does not require authentication. For this test, I temporarily commented out the authentication part. In this case, I received a response.
  • I checked if the configuration of ‘Ole Automation Procedures’ are enabled:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>sp_configure 'show advanced options', 1
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1
GO
RECONFIGURE;
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE;
</code>
<code>sp_configure 'show advanced options', 1 GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures', 1 GO RECONFIGURE; GO sp_configure 'show advanced options', 1 GO RECONFIGURE; </code>
sp_configure 'show advanced options', 1 
GO 
RECONFIGURE; 
GO 
sp_configure 'Ole Automation Procedures', 1 
GO 
RECONFIGURE; 
GO 
sp_configure 'show advanced options', 1 
GO 
RECONFIGURE;

New contributor

luca is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật