[Mono-bugs] [Bug 580714] New: SqlBulkCopy is Broken Badly
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Feb 17 17:28:18 EST 2010
http://bugzilla.novell.com/show_bug.cgi?id=580714
http://bugzilla.novell.com/show_bug.cgi?id=580714#c0
Summary: SqlBulkCopy is Broken Badly
Classification: Mono
Product: Mono: Class Libraries
Version: 2.6.x
Platform: 64bit
OS/Version: openSUSE 11.1
Status: NEW
Severity: Major
Priority: P5 - None
Component: Sys.Data.SqlClient
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: silenuznowan at yahoo.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
Description of Problem:
Code using SqlBulkCopy that runs fine in .Net does not work in Mono. I always
receive an exception.
However when running the code in windows through .Net there are no exceptions
and the data transfers fine.
Steps to reproduce the problem:
Create a MSSQL server database called MonoBulkCopyTest
Add table to the database with two nvarchar columns.
Add the following code to a winform application and run it.
//This line must be edited for the connection to the test database
String connectionString = "Data Source=****;Initial
Catalog=MonoBulkCopyTest;User ID=****;Pwd=****;";
//data table to bulk copy
DataTable dtdata;
//connection to sql server to do the copy
System.Data.SqlClient.SqlConnection con;
//bulk writer to do the actual copy
System.Data.SqlClient.SqlBulkCopy bulkWriter;
private void RunTest()
{
//create the connection to the database.
con = new System.Data.SqlClient.SqlConnection(connectionString);
//create the bulkcopy object
CreateBulkWriter();
//create the datatable
CreateTable();
//add some data to the datatable
AddData();
//try to bulk copy the datatable
CopyData();
}
/// <summary>
/// Create the data table to test the bulk copy with
/// </summary>
private void CreateTable()
{
//create the dtdata datatable to hold information for the bulk copy
to the
//Movie table in the database
dtdata = new DataTable("table1");
//Create title column in dtdata datatable
dtdata.Columns.Add("title", System.Type.GetType("System.String"));
//Create year column in dtdata datatable
dtdata.Columns.Add("year", System.Type.GetType("System.String"));
}
/// <summary>
/// Create the bulkcopy object and set the column mappings
/// </summary>
private void CreateBulkWriter()
{
//create a bulk writer to efficently write the data
bulkWriter = new System.Data.SqlClient.SqlBulkCopy(con);
//set the destination table of the bulk writer to be the Movie
table
bulkWriter.DestinationTableName = "Movie";
//Map title from source to destination
bulkWriter.ColumnMappings.Add("title", "title");
//Map year from source to destination
bulkWriter.ColumnMappings.Add("year", "year");
}
/// <summary>
/// add some data to the datatable for the bulk copy
/// </summary>
private void AddData()
{
DataRow dr = dtdata.NewRow();
dr[0] = "Citizen Kane";
dr[1] = "1941";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "Casablanca";
dr[1] = "1942";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "The Godfather";
dr[1] = "1972";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "Gone With The Wind";
dr[1] = "1939";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "Lawrence Of Arabia";
dr[1] = "1962";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "The Wizard Of Oz";
dr[1] = "1939";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "The Graduate";
dr[1] = "1967";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "On The Waterfront";
dr[1] = "1954";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "Schindler's List";
dr[1] = "1993";
dtdata.Rows.Add(dr);
dr = dtdata.NewRow();
dr[0] = "Singin' In The Rain";
dr[1] = "1952";
dtdata.Rows.Add(dr);
}
/// <summary>
/// Attempts to bulk copy the datatable dtdata to the database
/// </summary>
private void CopyData()
{
try
{
con.Open();
bulkWriter.WriteToServer(dtdata);
entry1.Text = "Success";
}
catch (Exception ex)
{
//System.Windows.Forms.MessageBox.Show(ex.ToString(),"Exception
Thrown", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
entry1.Text = ex.ToString();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
Actual Results:
System.Data.SqlClient.SqlException: Invalid column type from bcp client for
colid 1.
at System.Data.SqlClient.SqlConnection.ErrorHandler (System.Object sender,
Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs e) [0x00032] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs:316
at Mono.Data.Tds.Protocol.Tds.OnTdsErrorMessage
(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs e) [0x0000b] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:1695
at Mono.Data.Tds.Protocol.Tds.ProcessMessage (TdsPacketSubType subType)
[0x000ef] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:1735
at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x00130] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:1787
at Mono.Data.Tds.Protocol.Tds.NextResult () [0x0004a] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:619
at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00005] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:692
at Mono.Data.Tds.Protocol.Tds.ExecBulkCopy (Int32 timeout, Boolean
wantResults) [0x0001f] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs:550
at Mono.Data.Tds.Protocol.TdsBulkCopy.BulkCopyEnd () [0x00015] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs:98
at System.Data.SqlClient.SqlBulkCopy.BulkCopyToServer (System.Data.DataTable
table, DataRowState state) [0x0053d] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/System.Data/System.Data.SqlClient/SqlBulkCopy.cs:424
at System.Data.SqlClient.SqlBulkCopy.WriteToServer (System.Data.DataTable
table) [0x00000] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/System.Data/System.Data.SqlClient/SqlBulkCopy.cs:448
at MainWindow.CopyData () [0x0000b] in
/home/jordan/projects/MonoSqlbulkCopyBug/MainWindow.cs:137
Or
System.IndexOutOfRangeException: Array index is out of range.
at Mono.Data.Tds.Protocol.TdsComm.AppendInternal (Int16 s) [0x00073] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:339
at Mono.Data.Tds.Protocol.TdsComm.Append (System.String s) [0x00075] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:389
at Mono.Data.Tds.Protocol.TdsComm.Append (System.Object o) [0x000d8] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:237
at Mono.Data.Tds.Protocol.TdsBulkCopy.BulkCopyData (System.Object o, Int32
size, Boolean isNewRow) [0x00034] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs:91
at System.Data.SqlClient.SqlBulkCopy.BulkCopyToServer (System.Data.DataTable
table, DataRowState state) [0x004aa] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/System.Data/System.Data.SqlClient/SqlBulkCopy.cs:412
at System.Data.SqlClient.SqlBulkCopy.WriteToServer (System.Data.DataTable
table) [0x00000] in
/usr/src/packages/BUILD/mono-2.6.1/mcs/class/System.Data/System.Data.SqlClient/SqlBulkCopy.cs:448
at IMDBDataExchange.SQLServerWriterBase.ClearCache () [0x00002] in
/home/jordan/projects/IMDBDataExchange/IMDBDataExchange/SQLServerWriterBase.cs:27
Expected Results:
Should bulk copy the data in the datatable to the database
How often does this happen?
Always
Additional Information:
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list