将平面文件导入 Microsoft SQL Server Management Studio 18 时出错 - “系统内存不足”

问题描述 投票:0回答:2

我有一个大约 10 GB 的 Excel CSV,我正在尝试将其导入到 SQL 数据库中。当我使用导入平面文件选项/向导时,文件开始导入大约 10-15 秒,然后出现系统内存不足异常错误。以下是错误输出和截图。

非常感谢任何信息!

Detailed Error Output:
Error inserting data into table. (Microsoft.SqlServer.Import.Wizard)

------------------------------
Program Location:

   at Microsoft.SqlServer.Import.Wizard.InsertData.ResultCheck(Result result)
   at Microsoft.SqlServer.Import.Wizard.InsertData.DoWork()
   at Microsoft.SqlServer.Management.TaskForms.SimpleWorkItem.Run()

===================================

Error inserting data into table. (Microsoft.SqlServer.Prose.Import.SDS)

------------------------------
Program Location:

   at Microsoft.SqlServer.Prose.Import.BcpTextSynthesis.InsertIntoDB(String inputFilePath, String tableName, String schemaName, IReadOnlyList`1 columnInfo, SqlConnection connection, Int32 batchSize, SqlTransaction transaction, IList`1 allFinalTransformations, IList`1 allFinalTransformationColumns, IList`1 allFinalColNames)
   at Microsoft.SqlServer.Prose.Import.BcpProcess.CreateTableAndInsertDataIntoDb(String connectionString, Int32 batchSize, String azureAccessToken)

===================================

Exception of type 'System.OutOfMemoryException' was thrown. (mscorlib)

------------------------------
Program Location:

   at System.Text.StringBuilder.ToString()
   at Microsoft.ProgramSynthesis.Read.FlatFile.Semantics.Semantics.<SplitLines>d__17.MoveNext()
   at Microsoft.ProgramSynthesis.Read.FlatFile.Semantics.Semantics.<Csv>d__9.MoveNext()
   at System.Linq.Enumerable.<SkipIterator>d__31`1.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.SqlServer.Prose.Import.BcpTextSynthesis.InsertIntoDB(String inputFilePath, String tableName, String schemaName, IReadOnlyList`1 columnInfo, SqlConnection connection, Int32 batchSize, SqlTransaction transaction, IList`1 allFinalTransformations, IList`1 allFinalTransformationColumns, IList`1 allFinalColNames)





[Image of Import Wizard][1]


[Error Image 'System.OutOfMemoryException' was thrown][2]
sql-server
2个回答
2
投票

我使用了批量插入命令,如下所示,请确保要加载的文件位于 SQL 服务器上,而不是本地/远程计算机上。

BULK INSERT dbo.TABLE
 FROM 'E:\YOUR_FILES.csv'
WITH ( FORMAT = 'CSV',
 FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n' );

1
投票

对于这样的大文件,请考虑使用批量插入

© www.soinside.com 2019 - 2024. All rights reserved.