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

2 Answers 2

20

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

4
  • 3
    I called session Session.SaveChanges out side of my 'foreach' and it worked perfectly Mar 23, 2011 at 21:47
  • 2
    You've been noticed: ayende.com/blog/4814/…. Perhaps you should rethink. May 12, 2011 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, 2018 at 6:04
  • Worked perfectly for me. Thanks!
    – Fabiano
    Jul 19, 2019 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;
      }
   }
3
  • 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 8, 2012 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 2, 2013 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, 2018 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.