Oracle - How to insert a string longer than 4k using C#

And this is another PITA sponsored by our good friends of Oracle ;)

After being struggling whit this issue for a whole day, I finally figure it out. There is a bunch of posts on the web saying that you should change the column type on the table from let’s say LONG to CLOB or stuff like that… but I have tried it and it has no effect if you are working with C# (maybe make sense if you are working with PL. I’m not sure, haven’t test it). The thing is even if you change the column type, you’ll still get an error saying “the string literal is too long…” The way to insert strings larger than 4K into Oracle databases is using bindings. And yes, you can insert 4k plus strings into LONG columns, there is no such 4k limit. This is how you do that:


* I skip error handling, disposing objects, etc… just for brevity, of course you shouldn't ;)

Another interesting thing that almost every posts got wrong is that you don’t have to specify the parameter type, the library will choose the right type for you. So don’t waste your time on that.

Comments

Popular posts from this blog

How to create MS Word documents from Office templates using C#

Printing html using the embedded web browser control

WinForms, paging the DataGridView the right way