I have text file of 550mb.When I run this code computer hangs after 10 mins and data insertion fails but this works fine for file of 100mb
public static void BulkUpdate(string col, System.IO.StreamReader sr, string tableName)
{
ConnStr = ConfigurationSettings.AppSettings["ConnStrAffiliate"].Trim();
SqlConnection myConn = DAO.fetchConnection();
string[] value = col.Split(new char[] { '\t' },StringSplitOptions.RemoveEmptyEntries);
DataTable dt = new DataTable();
DataRow row;
foreach (string dc in value)
{
dt.Columns.Add(new DataColumn(dc, typeof(string)));
}
while (!sr.EndOfStream)
{
value = sr.ReadLine().Split(new char[] { '\t' });
List<string> valueList = value.ToList();
valueList.RemoveAt(valueList.Count - 1);
value = valueList.ToArray();
if (value.Length == dt.Columns.Count)
{
row = dt.NewRow();
row.ItemArray = value;
dt.Rows.Add(row);
}
}
SqlBulkCopy bc = new SqlBulkCopy(ConnStr, SqlBulkCopyOptions.TableLock);
bc.DestinationTableName = tableName;
bc.BatchSize = dt.Rows.Count;
bc.WriteToServer(dt);
bc.Close();
}
I dont know what the problem was but i have tried Sql Server Integration services for reading and uploading the file into database.It was a success and takes much less time