SQL Server 2012 - Insufficient memory to continue the execution of the program. (mscorlib)
If you need to execute sql file use sqlcmd documented in the MSDN: Run Transact-SQL Script Files Using sqlcmd

This did the trick for me:

sqlcmd -S serverName\instanceName -i script.sql  -o output.txt