5

When I run data-only script in SQL Server 2008 R2, it is showing this error:

Cannot execute script
Additional information:
Exception of type 'System.OutOfMemoryException' was thrown. (mscorlib)

The size of script file is 115MB and it's only data .

When I open this script file, it shows:

Document contains one or more extremely long lines of text.  
These lines cause the editor to respond slowly when you open the file .  
Do you still want to open the file ?

I run schema-only script first and then data-only script .

Is there any way to fix this error ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
zey
  • 5,939
  • 14
  • 56
  • 110
  • Possible duplicate of [Cannot execute script: Insufficient memory to continue the execution of the program](https://stackoverflow.com/questions/17918770/cannot-execute-script-insufficient-memory-to-continue-the-execution-of-the-prog) – A-Sharabiani Dec 27 '17 at 16:37

3 Answers3

13

I solved it by using sqlcmd utitlity.

sqlcmd -S "Server\InstanceName" -U "instantName" -P "password" -i FilePathForScriptFile

For example :

sqlcmd -S .\SQLEXPRESS -U sa -P 123 -i D:\myScript.sql
naveen
  • 53,448
  • 46
  • 161
  • 251
zey
  • 5,939
  • 14
  • 56
  • 110
1

Zey's answer was helpful for me, but for completion:

If you want to use Windows Authentication just omit the user and password.

And don't forget the quotes before and after the path if you have spaces.

sqlcmd -S .\SQLEXPRESS -i "C:\Users\Stack Overflow\Desktop\script.sql"
Edu
  • 2,354
  • 5
  • 32
  • 36
0

If you're logged into the domain with the correct privileges and there's only one instance running, you also do not have to provide the above user/pw/instance command args. I was able to just execute:

sqlcmd -i myfile.sql

rigoo44
  • 95
  • 1
  • 8