title: How Read JSON Data From URL In SQL Server
body: <p>I'm trying to read JSON data from a URL in SQL Server 2008, using this code:</p>
  
  <pre class="lang-sql prettyprint-override"><code>DECLARE @temp table (RowNum int, DATA NVARCHAR(max))
  DECLARE @url VARCHAR(MAX),
  @win INT,
  @hr INT,
  @Text VARCHAR(8000),
  @RowID int,
  @Status smallint,
  @Accuracy tinyint
  
  Set @url = 'http://www.jsonprovider.com/api/json/2020'
  EXEC @hr = sp_OACreate 'WinHttp.WinHttpRequest.5.1', @win OUT
  IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win
  
  EXEC @hr = sp_OAMethod @win, 'Open', NULL, 'GET', @url, 'false'
  IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win
  
  EXEC @hr = sp_OAMethod @win, 'Send'
  IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win
  
  EXEC @hr = sp_OAGetProperty @win, 'ResponseText', @Text OUT
  IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win
  
  EXEC @hr = sp_OADestroy @win 
  IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @win 
  
  select  @Text  --&lt;&lt; Result
  </code></pre>
  
  <p>AND I get my result.</p>
  
  <p>The problem is the process to get this result takes 7 sec in SQL Server, but in normal call by C# application and calling in web browser I get my result in 0.06 sec.</p>
  
  <p>I looking for a solution for improving my code to get a fast result.</p>