ある SQL Server テーブルから別のテーブルにレコードをコピーしようとしています。両方のテーブルの構造は同じで、列の 1 つは xml 型です。ソース テーブルの行には、約 2.5Mb の大きな xml コンテンツがあります。
xml 列の内容をファイルに保存しました。添付の map.zip を参照するか、https://docs.google.com/leaf?id=0Bz4PXXEQL5TpM2U5MWJhM2MtMTI0Yi00ODg0LTk4OWItMzJiNjVjMDIzNjc2&hl=en&authkey=CLT5i8oP からダウンロードして ください。
私のコードの簡略版:
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);
}
}
}
}
}
bulkCopy.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-row-with-large-content-in-an-xml-column
彼らはこれが彼らのバグであることを確認しました:
これまでのデバッグから、一括コピー パスでの XML のサーバー側処理に問題があるように見えます。XML ファイル内の属性の 1 つが非常に大きく、割り当てサイズの制限により、XML の処理時に SQL Server が失敗する原因となっています。