views:

430

answers:

1

I'm trying to insert around 16000 records into a single table. Because this is very slow, I'd like to batch insert them. However, I'm always getting a timeout error when I attempt to do this. So I have two questions:

  1. What is the best way to speed up inserts?
  2. How do I increase the timeout value of the connection?
+1  A: 

First you have to use a stateless session. Instead of calling OpenSession(); (on the session factory), you call OpenStatelessSession(); It has much the same api as the normal session, but there is not caching and stuff (a lot quicker for bulking data operations). Then you need to set the batch size by calling .AdoNetBatchSize([[batch size]]); where you set the database in your configuration.

This might do the trick. But you should know that this isn't relay what nhibernate (or any other orm) is built for, so don't count on any kind of performance.

Mattias Jakobsson
Well, it was taking over 20 minutes (I never let it finish completely). Using this method it takes only a few seconds. Thank you!
Matthew Talbert
Great. Glad I could help.
Mattias Jakobsson