You are here
Home > SQL > Execute Script Error Resolved In SQL Server Management Studio

Execute Script Error Resolved In SQL Server Management Studio

Execute Script Error

Execute Script Error – Imagine my surprise when I tried executing a rather large SQL script (255 Mb) and received an error telling me that there was ‘Insufficient memory to continue the execution of the program. (mscorlib)’. You might be wondering why I would even have such a large script to begin with.

Looking for something else? Try these links instead:

Well I had to import data from a file that I didn’t have access to any more, so I decided to script the table contents from the live database and import into my dev database for testing. Trying to run the query produced the error and I had to find an alternative way to get the data into my table.

Execute Script Error – Workaround

Ok, so I guess this isn’t a workaround per se but a very definite method for running SQL scripts outside SQL Server Management Studio by running the script from the command-line.

Execute Script Error

What I did next was to copy the script to my temp folder. You can see that it is rather big (for basically a text file).

Execute Script Error

I then open the command prompt (it is wise to run as Administrator here) and then I changed the directory to the following:

C:Program FilesMicrosoft SQL Server100ToolsBinn

Execute Script Error

The next command I typed in was the following:

osql -S VM-PC -d SysproCompany0 -E -i C:tempbig_sql.sql

What this means is the following.

-S is your SQL server IP Address or Name

-d is the database name to run the script against

-E means trusted connect

So think of the command as follows:

osql -S [SQL Server IP/Name] -d [Database Name] -E -i [path to your sql script file]

When you execute this command, your script will be executed against the database you selected in your command. This is a nice and easy (not to mention quick) method for executing large scripts into a database. It also happens to be really easy on memory.

en aboFaisal, StackOverflow

Dirk Strauss
Dirk is a Software Developer from South Africa. He loves all things Technology and is slightly addicted to Jimi Hendrix. Apart from writing code, he also enjoys authoring books and articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has almost mastered.

Similar Articles