0
신청서에 심각한 문제가 있습니다. 큰 엑셀 파일을 읽는 동안 oledb.jet 12.0 프로 바이더를 통해 9 십만 개 이상의 레코드를 가져오고 언젠가는 시간이 지나면 반환 된 값에서 데이터 세트로 채우고 나에게 메시지를 잊어 버리는 예외가 있습니다.윈도우 서비스를 통해 큰 엑셀 파일을 업로드하는 중에 메모리 부족 예외가 발생합니다.
나는 그걸 해결하기 위해 열심히 노력했지만 지금까지는 운이 없다.
같은 문제에 대한 아이디어가 있으면 알려주십시오.
코드 :
MyConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FileSource & ";Extended Properties=""Excel 12.0;IMEX=1""")
MyConn.Open()
'get the table schema information to retrive sheet name
Dim schemaTable As DataTable = MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
For Each dtrow As DataRow In schemaTable.Rows
Dim iUploadStatus As Integer = 0
sheetName = String.Empty
sheet = dtrow("TABLE_NAME").ToString()
'to skip the duplicate sheet being fetched in the schema table.
If sheet.Contains("_xlnm#_FilterDatabase") Or sheet.Contains("_FilterDatabase") Then
Continue For
End If
MyCommand = New OleDbDataAdapter _
("select * from [" + sheet + "] ", MyConn)
MyCommand.TableMappings.Add("Table", "TestTable")
DtSet = New DataSet
MyCommand.Fill(DtSet)
Using destinationConnection As New SqlConnection(Conn)
' open the connection
destinationConnection.Open()
Using bulkCopy As New SqlBulkCopy(Conn)
' column mappings
bulkCopy.ColumnMappings.Add(P1, ColProdNum)
bulkCopy.ColumnMappings.Add(P2, ColProdDesc)
bulkCopy.ColumnMappings.Add(P3, ColListPrice)
bulkCopy.ColumnMappings.Add(P4, ColNetPrice)
bulkCopy.BatchSize = 2000
bulkCopy.NotifyAfter = 2000
bulkCopy.DestinationTableName = "tabDestination"
bulkCopy.WriteToServer(DtSet.Tables(0))
End Using
End Using
일부 코드를 게시 할 수 있습니까? – Dhawalk
... 모든 레코드를 한 번에 처리하지 마십시오. –
+1 to @PeterRitchie,하지만 그저 관심사로, 충돌 할 때 얼마나 많은 메모리를 사용하고 있습니까? 32 비트 프로세스를 실행하는 경우 [2GB] (http://stackoverflow.com/a/200356/622391)로 제한됩니다 ... –