0

I've to perform a bulk insert from an Azure function and I was wondering if there's a way of treating an IList<string> as IDataReader. As I've seen there're around some implementations that via reflection creates an IDataReader but I don't know how to process it when it's a string (';' separated value)

Thanks.

xGeo
  • 2,149
  • 2
  • 18
  • 39
advapi
  • 3,661
  • 4
  • 38
  • 73
  • 1
    What about converting the `;` separated string into a `List` and then doing what you're saying – dcg Jun 26 '17 at 13:22
  • I need to use them in a SqlBulkCopy that accepts an IDataReader ...since the source can be huge (1-2GB of source file) I wish to not have a copy in memory of the data – advapi Jun 26 '17 at 13:23
  • The correct answer in the duplicate is *use ObjectDataReader*. What you try to do though is *not* what the title says. An IDataReader is *not* a method of parsing strings. If you want to parse the string, well, parse it first, then send it to the database. Parsing does *not* mean loading everything in memory. – Panagiotis Kanavos Jun 26 '17 at 14:51
  • In fact, this looks like a case of the XY Problem. You have a problem X, assume the solution is Y and ask about Y when you get in trouble, instead of X. Where does the data come from? What is the actual size and format? Do you *really* get 2GB data *at once* ? Or do you receive events that you save into 2GB files? – Panagiotis Kanavos Jun 26 '17 at 14:54
  • Is the file a delimited file with `;` as the field delimiter? Or a line-delimited JSON? Why not read the file a line at a time, parse individual lines into concrete objects and feed *that* IEnumerable to ObjectDataReader? You don't need to load the entire text in memory – Panagiotis Kanavos Jun 26 '17 at 14:56
  • @advapi so this *is* an XY problem indeed, you already asked the *actual* question, didn't provide enough information, then asked *again* with an attempted solution Y, but still no schema info – Panagiotis Kanavos Jun 26 '17 at 14:59

0 Answers0