Sql-server – SQLCLR TVF that calls web service is getting error 401: Unauthorized

csql serversql-clrsql-server-2008-r2web service

I am calling a web service from a SQLCLR TVF in SQL Server 2008 R2.

On the IIS server this service has open permissions. When tested using GET or POST requests on a browser the web service works as expected. However, when the function calls the service, it returns:

The request failed with HTTP status 401: Unauthorized.

In the typical anecdotal way, when I run the TVF on my machine to access the service on my machine, it works. (proof that code is correct)

This error occurs when using a SQL Server on the network accessing another ISS server on the network. Both servers are in the same domain.

How to determine the missing permissions that prevent this TVF from working?

Best Answer

A couple basic SQL Server checks: Is your database set to trustworthy? Is the assembly set to allow UNSAFE execution?

If that seems to be working, there are a couple of tutorials out on the web that might help. If none of the tutorials out there help, then it sounds like a permissions issue. (Unfortunately, that gets tricky, as this thread discussing Kerberos versus NTLM authentication shows.)

One other check--as Maumen mentioned--make sure that you have anonymous access setup for IIS.

Ultimately, though, it sounds like something you want to avoid, if you can. The performance and memory implications, the difficulty getting all the accounts working, and decreasing all the security settings would make me a bit nervous.