나는 복사하는 파일의 크기가 때때로 600MB를 초과하여 실행되기 때문에 SQLBULKCOPY를 사용하여 일부 데이터 테이블을 데이터베이스 테이블에 복사하고 있는데, 메모리가 부족한 상태로 유지됩니다.sqlbulkcopy mem. 관리
데이터베이스에 커밋하기 전에 테이블 크기 관리에 대한 조언을 받기를 바란다. 그래서 나는 계속 쓰기 위해 약간의 메모리를 비울 수있다. 여기
내 코드의 예 내가 SqlBulkCopy의 작동하도록 점점 문제가 계속 SqlBulkCopy sqlbulkCopy = new SqlBulkCopy(ServerConfiguration); //Define the Server Configuration
System.IO.StreamReader rdr = new System.IO.StreamReader(fileName);
Console.WriteLine("Counting number of lines...");
Console.WriteLine("{0}, Contains: {1} Lines", fileName, countLines(fileName));
DataTable dt = new DataTable();
sqlbulkCopy.DestinationTableName = "[dbo].[buy.com]"; //You need to define the target table name where the data will be copied
dt.Columns.Add("PROGRAMNAME");
dt.Columns.Add("PROGRAMURL");
dt.Columns.Add("CATALOGNAME");
string inputLine = "";
DataRow row; //Declare a row, which will be added to the above data table
while ((inputLine = rdr.ReadLine()) != null) //Read while the line is not null
{
i = 0;
string[] arr;
Console.Write("\rWriting Line: {0}", k);
arr = inputLine.Split('\t'); //splitting the line which was read by the stream reader object (tab delimited)
row = dt.NewRow();
row["PROGRAMNAME"] = arr[i++];
row["PROGRAMURL"] = arr[i++];
row["CATALOGNAME"] = arr[i++];
row["LASTUPDATED"] = arr[i++];
row["NAME"] = arr[i++];
dt.Rows.Add(row);
k++;
}
// Set the timeout, 600 secons (10 minutes) given table size--damn that's a lota hooch
sqlbulkCopy.BulkCopyTimeout = 600;
try
{
sqlbulkCopy.WriteToServer(dt);
}
catch (Exception e)
{
Console.WriteLine(e);
}
sqlbulkCopy.Close();//Release the resources
dt.Dispose();
Console.WriteLine("\nDB Table Written: \"{0}\" \n\n", sqlbulkCopy.DestinationTableName.ToString());
}
(편의상 제거 약간의 열과 행), 그리고 나는 더 많은 일을 작업 할 필요가 실현 각 레코드가 데이터베이스에 입력되기 전에 레코드 업데이트로 레코드를 수행하는 간단한 LinQ Sql 메서드를 개발하여 다른 정보를 편집하고 실행되는 동안 더 많은 레코드 정보를 만들 수 있습니다.
문제점 : 방법은 예쁜 slo를 달리고있다. w (코어 i3 머신에서도), 속도 향상 방법 (스레딩?) - 단일 프로세서 코어에서 1GB의 메모리로 충돌하거나 때로는 6 ~ 8 시간이 소요되는 동일한 양의 데이터 쓰기 한 순간에 SQLBulkCopy가 발생합니다. 그것은 더 나은 기억을 잘 관리합니다. 도우미 방법으로
while ((inputLine = rdr.ReadLine()) != null) //Read while the line is not null
{
Console.Write("\rWriting Line: {0}", k);
string[] arr;
arr = inputLine.Split('\t');
/* items */
if (fileName.Contains(",,"))
{
Item = Table(arr);
table.tables.InsertOnSubmit(Item);
/* Check to see if the item is in the db */
bool exists = table.tables.Where(u => u.ProductID == Item.ProductID).Any();
/* Commit */
if (!exists)
{
try
{
table.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
// Make some adjustments.
// ...
// Try again.
table.SubmitChanges();
}
}
}
:
public static class extensionMethods
{
/// <summary>
/// Method that provides the T-SQL EXISTS call for any IQueryable (thus extending Linq).
/// </summary>
/// <remarks>Returns whether or not the predicate conditions exists at least one time.</remarks>
public static bool Exists<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
return source.Where(predicate).Any();
}
}
또한 RDR 폐기 좋은 생각을 –
덕분에 수 있습니다 - 내가 전에 내 독자를 처분 만약 내가, 내가 궁금하네요 마음 에 그하겠습니다 나는 각 파일을 읽는 것을 끝내기 전에 독자를 끝내기 전에 내가 쓰는 동안 내가 읽지 않는 동안 내가 곧바로 읽고있는 동안 나는 나의 페이스를 느슨하게 할 것이고, 나는 메모리 오류를 가지고있다. 어떤 생각 내가 파일에 있던 곳으로 어떻게 뛰어 돌아갈 것인가? –
위의 코멘트를 참조하십시오 ... –