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
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.
- Display Line Numbers in SQL Server Management Studio (SSMS)
- How to Enable and Refresh IntelliSense in SQL Server Management Studio (SSMS)
- Performance Dashboard Reports in SQL Server 2012
- How to Use Dedicated Administrator Connection in SQL Server
- How to Migrate Existing Database to Partially Contained Database in SQL Server
- How to Configure Network Drive to be Visible for SSMS to Perform Database Backup and Restore?
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
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.