SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible working on iis express but not on iis code example

Example 1: the request was aborted could not create ssl/tls secure channel. c# restsharp

//Add this line of code before RestClient
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Example 2: Cannot connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager.

C:\Program Files (x86)\Microsoft SQL Server\140\Shared>mofcomp sqlmgmproviderxpsp2up.mof