c# - Can I insert a large text value into SQL Server from ASP.net without having the whole file in memory on the webserver? -
as says in question, given large text file, how can contents nvarchar(max) column in sql server without loading entire file contents memory (either build dynamic sql statement or sp parameter)?
my best solution far insert row empty value , in loop run updates appending chunks of data each time in transaction. there better way other copying file database server , using bcp? way stream data over?
as of .net4.5 sqlparameters support textreader
https://msdn.microsoft.com/en-us/library/hh556234(v=vs.110).aspx
using (sqlconnection conn = new sqlconnection(connection_string)) using (sqlcommand cmd = conn.createcommand()) using (filestream file = file.openread(@"c:\temp\bigtextfile.txt")) { cmd.commandtext = "insert randomtable (textblob) values (@text)"; cmd.parameters.add("@text", system.data.sqldbtype.nvarchar, -1).value = file; conn.open(); cmd.executenonquery(); }
Comments
Post a Comment