Last post Jan 26, 2018 03:49 PM by jayakumarvinayagam
Jan 25, 2018 07:32 AM|JagjitSingh|LINK
I am executing sql script it is giving me error 'An unhandled exception of type System.Outofmemoryexecption' occurred in mscorlib.dll. File size is more than 10 G.B
Jan 25, 2018 09:01 AM|DA924|LINK
it is where you can post.
Jan 26, 2018 08:36 AM|X.Daisy|LINK
According to your description, it seems that the file is too large to load it in memory.
The file is too big, we'd better to not read it at one time. You can use StreamReader.ReadLine() to read the file line by line.
using(StreamReader sr=new StreamReader(@"D:\Daisy\sqltest.txt"))
sqlstatements+=sr.ReadLine();//sr.ReadLine() will read data line by line.
Jan 26, 2018 08:43 AM|PatriceSc|LINK
More likely you try to load the full script in memory ? It should run in chunks (do you have "go" delilmiters in this script).
If this is a one time operation, you could also try a command line tool (that may run the script in chunks already). If not I would try to see if there is no better option than a huge SQL script for this data transfert.
Jan 26, 2018 03:49 PM|jayakumarvinayagam|LINK
Would you please try sqlcmd command, open Command prompt window with administrator access, type below command.
sqlcmd -s <<ServerName>> -i <<file path with extension >>
If you wanna save execution summary, use windows powershell and execute the same sqlcmd.
Note: please make sure your file properly designed.