title: Weird "OLE DB provider 'STREAM' for linked server '(null)' returned invalid data for column '[!BulkInsert].Value' error
body: <p>Software used: Windows 7 64 bit Ultimate, .Net 4, SQL Server 2008 R2.</p>
  
  <p>select @@version returns:</p>
  
  <pre><code>Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64)   Apr 22 2011 19:23:43   Copyright (c) Microsoft Corporation  Developer Edition (64-bit) on Windows NT 6.1 &lt;X64&gt; (Build 7601: Service Pack 1) (Hypervisor) 
  </code></pre>
  
  <p>To reproduce, and assuming you have a local sql server 2008 R2 instance, paste the following code in linqpad and run it as a Program.</p>
  
  <p>It blows up with:</p>
  
  <p>OLE DB provider 'STREAM' for linked server '(null)' returned invalid data for column '[!BulkInsert].Value'. </p>
  
  <pre><code>void Main()
  {
    SqlConnection cn = new SqlConnection("data source=localhost;Integrated Security=SSPI;initial catalog=tempdb;Connect Timeout=180;");
    cn.Open();
  
    IList&lt;decimal&gt; list = new List&lt;decimal&gt;() {-8m, 8m};
  
    decimal result = list.Sum(x =&gt; x);
  
    Console.WriteLine(result == 0);
  
    string tableName = "#test";
  
    CreateTemporaryTable(cn, tableName,
          String.Format(@"
            create table {0} (
              Value sql_variant
           );
         ", tableName));
  
    SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(cn);
    sqlBulkCopy.DestinationTableName = tableName;       
  
    DataTable dt = new DataTable();
    dt.Columns.Add("Value", typeof(object));
    dt.Rows.Add(result);
    sqlBulkCopy.WriteToServer(dt);
  
    sqlBulkCopy.Close();
  
    cn.Close();
  }
  
  // Define other methods and classes here
  
  
  public static void CreateTemporaryTable(SqlConnection cn, string destinationTableName, string createTableStatement)
  {
    string objectIdValue = (destinationTableName.StartsWith("#") ? "tempdb.." : "") + destinationTableName;
    string sql = String.Format(@" 
      if (object_id (N'{0}', N'U') is not null)
        begin
          drop table {1};
        end;
        {2}    
        ", objectIdValue, destinationTableName, createTableStatement);
  
  //      Console.WriteLine(sql);
    SqlCommand cmd = new SqlCommand(sql, cn);
    try
    {
      cmd.ExecuteNonQuery();
    }
    finally
    {
      cmd.Dispose();
    }
  }
  </code></pre>
  
  <p>I will probably create a case with Microsoft, but I was curious to see if someone else saw this before, and if there are any workarounds. It seems that not all the zeros are created equal.</p>
  
  <p>Just an update:</p>
  
  <p>I opened a case with Microsoft. It took them almost 2 months to come up with some obscure undocumented dbcc flag that turns off the validation of the values that get pumped via the bulk copy into the variant column. The case was bounced between the different teams (the support was provided by Indian private contractors) and they never got to the root problem which I think it is related to the value produced by the following lines and how it is handled by the bulk copy code :</p>
  
  <pre><code>  IList&lt;decimal&gt; list = new List&lt;decimal&gt;() {-8m, 8m};
    decimal result = list.Sum(x =&gt; x);
  </code></pre>
  
  <p>So, to conclude, it was disappointing and I gave up because it is a rare occurrence.</p>