You are currently viewing Execute Script Error Resolved In SQL Server Management Studio

Execute Script Error Resolved In SQL Server Management Studio

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

As a seasoned software developer with a long-standing career in C# and Visual Studio, I have had the privilege of working with a number of companies and learning from some of the most talented individuals in the industry. In addition to my professional experience, I have authored multiple books on topics such as C#, Visual Studio, and ASP.NET Core. My passion for programming is unwavering, and I am dedicated to staying current with the latest technology and sharing my expertise with others.