Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while running 50 MB script on SQL Server 2008 R2

People also ask

How do I run a SQL script in SQL Server 2008 Management Studio?

Click Query > Connection > Connect to connect to the server that contains the database you want to access. Select the appropriate StarTeam Server database. Open the tuning script, by choosing File > Open > foldername\scriptname. Execute the script, by clicking the Execute button on the toolbar or by pressing F5.

Is SQL Server 2008 R2 still supported?

Windows Server 2008/2008 R2 and SQL Server 2008/2008 R2 have both met their end-of-life dates: July 9, 2019 for SQL Server 2008/2008 R2 and January 14, 2020 for Windows Server 2008/2008. If you're still running any of those machines, you're doing so at your own risk—especially in this age of cyberattacks.


use the command-line tool SQLCMD which is much leaner on memory. It is as simple as:

SQLCMD -d <database-name> -i filename.sql

You need valid credentials to access your SQL Server instance or even to access a database


Adding to @user1293068's answer, I needed to specify the instance name. Here is my full syntax:

sqlcmd -S <ComputerName>\<InstanceName> -d <DatabaseName> -i <MyScript.sql>

This is documented on Technet's Use the sqlcmd Utility article.

(Note that you must enter a switch value of "-S", not "-s". The switch is case-sensitive.)


If credentials are required

sqlcmd -S <ComputerName>\<InstanceName> -U <username> -P <password> -d <DatabaseName> -i <MyScript.sql>

You can also try increasing the Maximum Server Memory 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.