16

If I'm trying to save a list of items I want to save that has a count > 30 I get an error saying

The maximum number of requests (30) allowed for this session has been reached. Raven limits the number of remote calls that a session is allowed to make as an early warning system. Sessions are expected to be short lived, and Raven provides facilities like Load(string[] keys) to load multiple documents at once and batch saves.

What can I do to get around this? The problem with this error is I'm not loading, I'm trying to save documents. Any ideas would be appreciated. Thank you

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291

2 Answers2

20

Call Session.Store with each of your objects before you call Session.SaveChanges.

T3hc13h
  • 602
  • 6
  • 15
  • 3
    I called session Session.SaveChanges out side of my 'foreach' and it worked perfectly – Kai CriticallyAcclaimed Cooper Mar 23 '11 at 21:47
  • 2
    You've been noticed: http://ayende.com/blog/4814/ravendb-safe-by-default-design-ndash-it-works. Perhaps you should rethink. – edoloughlin May 12 '11 at 12:15
  • Hmm... Monitoring `(Session as Raven.Client.Document.InMemoryDocumentSessionOperations).NumberOfRequests` property told me that the number is raising on each `SaveChanges()` call (call it after `Session.Store`) and fails on reaching `MaxNumberOfRequestsPerSession`... I'm using RavenDb 3.5 and still puzzled by what is resetting this number... – Alex Klaus Mar 27 '18 at 06:04
  • Worked perfectly for me. Thanks! – Fabiano Jul 19 '19 at 17:53
18

Although not recommended, in special cases, you can set the Session.Advanced.MaxNumberOfRequestsPerSession property.

using (var docStore = store.Initialize())
   {
     using (var session = docStore.OpenSession())
      {
         session.Advanced.MaxNumberOfRequestsPerSession = 100;
      }
   }
WeSam Abdallah
  • 1,050
  • 1
  • 10
  • 16
  • 1
    Upvoted as there are legitimate reasons you might want to set this higher. 1000 is perhaps too much. A legitimate reason might be you are doing a number of transactions, but only want to fail if one save fails. The error is to warn devs from doing something stupid. – DalSoft Aug 08 '12 at 16:41
  • where to place that code??? means to say that place it when the connection is initialized or when opening session – Mohsin Oct 02 '13 at 12:47
  • Small increase of `MaxNumberOfRequestsPerSession` (e.g. up to 100) can be justified, but a need of a bigger number, should be treated as a red flag and may indicate necessity to rethink your approach. – Alex Klaus Mar 26 '18 at 04:50