MyTechMantra.com

How to Fix Cannot execute script. Insufficient memory to continue the execution of the program (mscorlib) error in SQL Server

Introduction

Database Administrators often need to get involved in code deployments wherein they release new code from one environment to another. As a best practice it is highly recommended to note down issues faced during code deployment and address them before you move with code deployment to higher environments such as Pre-Production or Production.

One of the most errors faced by DBAs during code deployment is “Cannot execute script. Insufficient memory to continue the execution of the program (mscorlib)“. The reason why you receive the above error is SQL Server Management Studio is when SSMS cannot handle errors in case if the script fails because the script file is very big generally above 30 MB.

How to Fix Insufficient memory to continue the execution of the program (mscorlib) error in SQL Server

Insufficient memory to continue the execution of the program (mscorlib)

Error Message

Cannot execute script. Insufficient memory to continue the execution of the program (mscorlib)

Solution: Use SQLCMD to execute Large TSQL Scripts

SQL Server Management Studio (SSMS) is not always the right option to execute larger script files. Hence it is highly recommended to use SQLCMD utility from command prompt to execute larger files.

Related Articles

How to Start SQLCMD Command Line Utility

1. On the Start menu click Run. In the Open box type cmd, and then click OK to open a Command Prompt window.

2. In the command prompt, type SQLCMD.

3. Press ENTER.

You will now have a trusted connection to the default instance of SQL Server that is running on your computer. 1> is the sqlcmd prompt that specifies the line number. Each time you press ENTER, the number increases by one.

4. Finally to end the sqlcmd session, type EXIT at the sqlcmd prompt.

How to Run a Script on Standalone SQL Server Instance Using SQLCMD Command Line Utility

sqlcmd -S DATABASESERVERNAME -i "F:/DeploymentScripts/DataPopulation.sql" 

How to Run a Script on a Named Instance of SQL Server Using SQLCMD Command Line Utility

sqlcmd -S DATABASESERVERNAME\TESTINSTANCE -i "F:/DeploymentScripts/DataPopulation.sql" 

Overview of Different SQLCMD Command Line Options in SQL Server

-S Specifies the instance of SQL Server to which to connect 
-i Specify the file path of the input script 

Conclusion

It is highly recommended to use SQLCMD command line utility to execute TSQL scripts which are large in size as SQL Server Management Studio will not be able to handle large file for execution
Avatar

Chetna Bhalla

Newsletter Signup!



Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Recent SQL Server Tips

Manning