CSOM Error – Exception calling “ExecuteQuery” with “0” argument(s): The underlying connection was closed

I woke up one morning and seen majority of my scripts started failing with error:

Exception calling “ExecuteQuery” with “0” argument(s): The underlying connection was closed

On troubleshooting, it was found these were all scripts where I have utilized SharePoint Client Object Model (CSOM).

After a thought I immediately pin pointed it to TLS 1.2 So I used below command that I have mentioned in the article.

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

This helped but for that particular session only but what we wanted is that it is defaulted to TLS1.2 for every session.

On researching, I have found the solution that will persist and is independent of the sessions on the machine.

Open Powershell and check which cryptography protocols are currently available

 

[Net.ServicePointManager]::SecurityProtocol


 

Now update the registry key by using below commands

Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord

Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord

Restart PowerShell session: If you will check protocols again using

[Net.ServicePointManager]::SecurityProtocol

 

You will see tls12 in the list (these commands are forcing to utilize the higher encryption protocols)


This will resolve the issues related to tls1.2 permanently for all your scripts.

Reference found from: https://www.inflectra.com/Support/KnowledgeBase/KB510.aspx

 

Thanks for reading….

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Cheat Book

 

2 thoughts on “CSOM Error – Exception calling “ExecuteQuery” with “0” argument(s): The underlying connection was closed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s