我試圖將記錄從一個SQL Server表複製到另一個表。 兩個表具有相同的結構,其中一列是xml類型。 源表中有大量的xml內容,大約2.5Mb。SqlBulkCopy嘗試在XML列中複製含有大量內容的行時失敗
我保存XML列的內容到一個文件中,看到map.zip連接或 https://docs.google.com/leaf?id=0Bz4PXXEQL5TpM2U5MWJhM2MtMTI0Yi00ODg0LTk4OWItMzJiNjVjMDIzNjc2&hl=en&authkey=CLT5i8oP
簡化我的代碼版本下載:上bulkCopy發生
string query = "select * from MyTableSource where id = 1";
using (SqlConnection targetConnection = new SqlConnection(connectionStringTarget))
{
targetConnection.Open();
using (SqlConnection sourceConnection = new SqlConnection(connectionStringSource))
{
sourceConnection.Open();
using (SqlCommand command = new SqlCommand(query, sourceConnection))
{
using (IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(targetConnection))
{
bulkCopy.DestinationTableName = "MyTableTarget";
bulkCopy.WriteToServer(reader);
}
}
}
}
}
例外。 WriteToServer:
System.Data.SqlClient.SqlException was unhandled
Message=XML parsing: Document parsing required too much memory
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=6303
Procedure=""
Server=myserver
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal()
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32 columnCount)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(IDataReader reader)
at SyncTest.Form1.buttonCopyXml_Click(Object sender, EventArgs e) in C:\..\Form1.cs:line 2251
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at SyncTest.Program.Main() in C:\..\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
它看起來像一個SqlBulkCopy錯誤。 我想知道是否有人可以複製並確認。
更新: 它提起微軟,
_HTTPS://connect.microsoft.com/VisualStudio/feedback/details/614046/sqlbulkcopy-fails-trying-to-copy-a-行與大型化內容在-AN-XML列
他們證實這是他們的錯誤:
從迄今調試,看起來像一個在大容量複製路徑中處理XML的服務器端問題。 XML文件中的一個屬性非常大,並且由於分配大小的限制,導致SQL Server在處理XML時失敗。
非常有幫助。同樣的錯誤會影響使用SSIS向XML列大量導入大量文本。在SQL Server 2008 R2上發現了這一點。 – 2012-07-11 15:03:34