Cannot execute script: Insufficient memory to continue the execution of the program

SqlTsqlSql Server-2012

Sql Problem Overview


I have a 123MB sql file which I need to execute in my local PC. But I am getting

Cannot execute script: Insufficient memory to continue the execution of the program

enter image description here

How to solve this issue?

Sql Solutions


Solution 1 - Sql

> use the command-line tool SQLCMD which is much leaner on memory. It is as simple as: > > SQLCMD -d -i filename.sql > > You need valid credentials to access your SQL Server instance or even to access a database

Taken from here.

Solution 2 - Sql

It might help you! Please see below steps.

> sqlcmd -S server-name -d database-name -i script.sql

  • Open cmd.exe as Administrator.
  • Create Documents directory.
  • Put your SQL Script file(script.sql) in the documents folder.
  • Type query with sqlcmd, server-name, database-name and script-file-name as like above highlighted query or below command line screen.

enter image description here

Solution 3 - Sql

For Windows Authentication use this sql cmd

SQLCMD -S TestSQLServer\SQLEXPRESS  -d AdventureWorks2018 -i "d:\document\sql document\script.sql"

Note: If there is any space in the sql file path then use " (Quotation marks) "

For SQL Server Authentication use this sql cmd

SQLCMD -S TestSQLServer\SQLEXPRESS -U sa -P sasa  -d AdventureWorks2018 -i "d:\document\sql document\script.sql"

> -S TestSQLServer\SQLEXPRESS: Here specify SQL Server Name >
> -U sa: Username (in case of SQL Server Authentication) >
> -P sasa: Password (in case of SQL Server Authentication) >
> -d AdventureWorks2018: Database Name come here >
> -i "d:\document\sql document\script.sql": File Path of SQLFile

Solution 4 - Sql

You can also simply increase the Minimum memory per query value in server properties. To edit this setting, right click on server name and select Properties > Memory tab.

I encountered this error trying to execute a 30MB SQL script in SSMS 2012. After increasing the value from 1024MB to 2048MB I was able to run the script.

(This is the same answer I provided here)

Solution 5 - Sql

My database was larger than 500mb, I then used the following

C:\Windows>sqlcmd -S SERVERNAME -U USERNAME -P PASSWORD -d DATABASE -i C:\FILE.sql

It loaded everything including SP's

*NB: Run the cmd as Administrator

Solution 6 - Sql

If I understand your problem correctly, you are trying to restore (transact sql) xyz.sql - database + schema. You can try this command which worked for me:

SQLCMD -U sa -i xyz.sql

Solution 7 - Sql

Sometimes, due to the heavy size of the script and data, we encounter this type of error. Server needs sufficient memory to execute and give the result. We can simply increase the memory size, per query.

You just need to go to the sql server properties > Memory tab (left side)> Now set the maximum memory limit you want to add.

Also, there is an option at the top, "Results to text", which consume less memory as compare to option "Results to grid", we can also go for Result to Text for less memory execution.

Solution 8 - Sql

Try this step,

1)Open PowerShell

2)Write this command:

sqlcmd -S PCNAME\SQLEXPRESS -U user -P password -d databanse_name -i C:\script.sql

3)Press Return

:-)

enter image description here

Solution 9 - Sql

Below script works perfectly:

sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql -x

Symptoms:

When executing a recovery script with sqlcmd utility, the ‘Sqlcmd: Error: Syntax error at line XYZ near command ‘X’ in file ‘file_name.sql’.’ error is encountered.

Cause:

This is a sqlcmd utility limitation. If the SQL script contains dollar sign ($) in any form, the utility is unable to properly execute the script, since it is substituting all variables automatically by default.

Resolution:

In order to execute script that has a dollar ($) sign in any form, it is necessary to add “-x” parameter to the command line.

e.g.

Original: sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql

Fixed: sqlcmd -s Server_name -d Database_name -E -i c:\Temp\Recovery_script.sql -x

Solution 10 - Sql

sqlcmd -S mamxxxxxmu\sqlserverr -U sa -P x1123 -d QLDB -i D:\qldbscript.sql

  • Open command prompt in run as administrator

  • enter above command

"mamxxxxxmu" is computer name "sqlserverr" is server name "sa" is username of server "x1123" is password of server "QLDB" is database name "D:\qldbscript.sql" is sql script file to execute in database

Solution 11 - Sql

If you need to connect to LocalDB during development, you can use:

sqlcmd -S "(localdb)\MSSQLLocalDB" -d dbname -i file.sql

Solution 12 - Sql

As in most answers given here use the command-line tool. In my case the script already has database creation code. If your script contains CREATE DATABASE command, for example

USE [master]
GO
CREATE DATABASE [your-database-name]

Then do not use the -d your-database-name, instead use the following command.

For Windows Authentication use the command

sqlcmd -S ServerName\InstanceName -i "script.sql" -x

For SQL Server Authentication use the command

sqlcmd -S ServerName\InstanceName -U usename -P password -i "script.sql" -x

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionImran Qadir Baksh - BalochView Question on Stackoverflow
Solution 1 - SqlThangamani PalanisamyView Answer on Stackoverflow
Solution 2 - SqlAnil SinghView Answer on Stackoverflow
Solution 3 - SqlManjunath BilwarView Answer on Stackoverflow
Solution 4 - SqldstetsenkoView Answer on Stackoverflow
Solution 5 - SqlZubeid HendricksView Answer on Stackoverflow
Solution 6 - Sqluser3228486View Answer on Stackoverflow
Solution 7 - SqlAnkita shrivastavaView Answer on Stackoverflow
Solution 8 - Sqldaniele3004View Answer on Stackoverflow
Solution 9 - SqlNimesh khatriView Answer on Stackoverflow
Solution 10 - SqlMahmaood aliView Answer on Stackoverflow
Solution 11 - SqllukyerView Answer on Stackoverflow
Solution 12 - SqlDushView Answer on Stackoverflow