Tuesday, May 01, 2018

TLS 1.2 and .NET Support: How to Avoid Connection Errors

I recently ran into an interesting issue when developing we are connecting to a third-party Carrier API. When trying to connect to the API endpoint, I received the following error message:

“An error occurred while making the HTTP request to https://<API endpoint>. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.” Inner exception was “Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.”

With data security in place lot of API providers are ending TLS 1.0 support. This can be overcomed by adding a line of code in .NET by setting TLS 1.1 or above
The default System.Net.ServicePointManager.SecurityProtocol in both .NET 4.0/4.5 is SecurityProtocolType.Tls|SecurityProtocolType.Ssl3.

.NET 4.0 supports up to TLS 1.0 while .NET 4.5 supports up to TLS 1.2

However, an application targeting .NET 4.0 can still support up to TLS 1.2 if .NET 4.5 is installed in the same environment. .NET 4.5 installs on top of .NET 4.0, replacing System.dll

Adding below one line of code will help you to avoid above error.

ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 |
(SecurityProtocolType)768 | (SecurityProtocolType)3072;

Reference:

namespace System.Net
{
    [System.Flags]
    public enum SecurityProtocolType
    {
       Ssl3 = 48,
       Tls = 192,
       Tls11 = 768,
       Tls12 = 3072,
    }
}

SQL Server 2016 Service Pack 2 (SP2) released !!!

The SQL Server 2016 Service Pack 2 (SP2) contains a rollup of released hotfixes as well as multiple improvements centered around performance, scalability, and supportability based on feedback from customers and the SQL community. These improvements enable SQL Server 2016 to perform faster and with expanded supportability and diagnostics. 

SQL Server 2016 Service Pack 2 includes:

  • Performance and scale improvements for SQL Server, such as improved database backup performance on large memory machines and added backup compression support, which helps performance of almost all databases.
  • Supportability and diagnostics enhancements, such as improved troubleshooting and additional information about statistics used during query plan optimization.

Monday, April 30, 2018

SSMS: Index was outside the bounds of the array. (Microsoft.SqlServer.Smo)

We will see this when we connect to SQL Server 2012 from SQL Server 2008/2008 R2

smo

Cause
This issue occurs because of an error in SSMS 2008 R2.

Solution
The problem is generated due to an error in SQL Server Management Studio 2008 & 2008 R2.

Fix
To solve this, apply the latest service pack available.

Quick Note: How to find out which Service Pack is installed on SQL Server?

-- SQL Server 2000/2005/2008/2008R2/2012
SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

-- SQL Server 6.5/7.0
SELECT @@VERSION

Monday, April 23, 2018

Difference between HTTP.SYS and WAS in IIS

HTTP.SYS (Hypertext Transfer Protocol Stack) is the kernel level components of IIS. All client request comes from client hit the HTTP.Sys of Kernel level. HTTP.SYS then makes a queue for each and every request for each and individual application pool based on the request.

Whenever we create any application pool IIS automatically registers the pool with HTTP.SYS to identify the particular during request processing.


WAS(Windows Activation Service) is a new feature of IIS, that allows all the features of the Windows Communication Framework stack, like non-HTTP channels and other stuff.

IIS is the web server that hosts the services that are activated via WAS.

WAS - is the new process activation mechanism that ships with IIS 7.0. WAS builds on the existing IIS 6.0 but is more powerful because it provides support for other protocols besides HTTP, such as TCP and Named Pipes.

For more details, go through IIS architecture