IDataReader implementation failure with SqlCeBulkCopy

c# idatareader sqlbulkcopy sql-server-ce

Question

I'm attempting to bulk load data into a SQL CE 4.0 file from a.DAT file that contains SQL Server output. ErikEJ's SqlCeBulkCopy class has been working fine for me to load data from SQL Server, however loading data from.DAT has been problematic.

To read from.DAT, I constructed a class that implements IDataReader, which I can then provide to the SqlCeBulkCopy.WriteToServer function. The reader generally appears to be working OK, but I'm having issues with nulls; when a null has been read from the.DAT file and is being placed into a nullable column in the target table, an exception is raised.

I'm inclined to think that the method I developed the IDataReader interface was flawed. The values are kept in a System.Object array, and the IsDBNull function is implemented as follows:

public bool IsDBNull(int i)
{
   return Values[i] == null;
}

It's important to note that even though I've set a breakpoint, the function is not being called.

If not, the appropriate techniques I use are:

    public object GetValue(int i)
        {
            return Values[i] ?? DBNull.Value;
        }
    object IDataRecord.this[int i]
        {
            get { return GetValue(i); }
        }

    object IDataRecord.this[string name]
        {
            get
            {
                return GetValue(GetOrdinal(name));
            }
        }

A FormatException with the message "Input string was not in a proper format" is the error I encounter. Does anybody know where I'm going wrong?

The stack trace for the exception looks like this:

  at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToByte(String value, IFormatProvider provider) at System.Data.SqlServerCe.SqlCeUpdatableRecord.SetClrTypeValue(Int32 ordinal, Object value, String method) at System.Data.SqlServerCe.SqlCeUpdatableRecord.SetValue(Int32 ordinal, Object value) at ErikEJ.SqlCe.SqlCeBulkCopy.WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) at ErikEJ.SqlCe.SqlCeBulkCopy.WriteToServer(IDataReader reader) at MySoftware.Modules.Analysis.SqlCeFileConfiguration.SqlCeBulkDataStreamer.CopyFromReader(IDataReader reader, String destinationConnectionString, String tableName) in E:\Code\Desktop MySoftware\software\desktop_and_web\MySoftware\MySoftware.Analysis\SqlCeFileConfiguration\SqlCeBulkDataStreamer.cs:line 42 at MySoftware.Modules.Analysis.Services.SqlCeDataManagerService.InsertData(String connectionString, String tempWorkFolder, TableInfo tableInfo) in E:\Code\Desktop MySoftware\software\desktop_and_web\MySoftware\MySoftware.Analysis\Services\SqlCeDataManagerService.cs:line 742

1
1
11/14/2013 11:50:53 AM

Accepted Answer

It turns out that the issue was something I overlooked; the source was really an empty string rather than null. It seems that I converted incorrectly when I read from the.DAT file.

0
11/14/2013 12:22:20 PM

Popular Answer

Do your imported data include any numeric values? It seems to be attempting to convert or parse an int but failing.



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow