Been trying to run a quite big sql script on MS SQL 2005 getting Exception of type System.OutOfMemoryException was thrown. (mscorlib)
The solution is simple, run the following CMD command:

sqlcmd -S YOURSQLSERVER\INSTANCENAME -U YOURUSERNAME -P YOURPASSWORD -d YOURDATABASE -i "c:\somescript.sql"

Note that the parameters like -U and -P are case sensitive!