51

I used RavenDB-Embedded 2.0.2230 in my application interacted with ASP .Net Web API in different assemblies.

When I set UseEmbeddedHttpServer = true on the document store, first time I send a request to RavenDB, it executes properly but when I try for the second time my application displays Raven Studio.

When I remove UseEmbeddedServer setting, my application runs without any problems.

My RavenDB is configured with the following codes in data tier :

this.documentStore = new EmbeddableDocumentStore
{
    ConnectionStringName = "RavenDB",
    UseEmbeddedHttpServer = true
}.Initialize();

and implementation of Web.config have these settings in the service tier :

<connectionStrings>
    <add name="RavenDB" connectionString="DataDir=~\App_Data\RavenDatabase" />
</connectionStrings>

Is there a setting I missed?

Is there any settings I need to apply to point Raven Studio to a different port?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Mohsen Alikhani
  • 1,657
  • 3
  • 19
  • 37
  • 1
    @MohsenAlikhani after you instantiate the `DocumentStore`, but before you call `Initialize()` on it you can do `documentStore.Configuration.Port = ` – Cristian Lupascu Nov 27 '12 at 09:24
  • `Configuration` property is unknown for `Raven.Client.IDocumentStore` of RavenDB-Embedded Unstable version. – Mohsen Alikhani Nov 27 '12 at 10:42
  • 2
    Correct, it's not on the `IDocumentStore` interface because that's used for non-embedded also. It is on the `EmbedddableDocumentStore` implementation. If you are passing an `IDocumentStore`, just cast it back. `((EmbeddableDocumentStore)mystore).Configuration.Port = 8080` – Matt Johnson-Pint Dec 14 '12 at 22:03
  • I think you can make it work by changing the config options for the server so it works on another host:port combo, check [Here](http://ravendb.net/docs/server/administration/configuration?version=2.0) and look for Http settings. – VoidMain Jan 08 '13 at 22:11
  • ask this on ravendb google groups list: https://groups.google.com/forum/?fromgroups#!forum/ravendb – wal Jan 12 '13 at 08:12
  • Can you please stop making so many of these minor edits to bump your question? If you need an answer, start a bounty instead. – BoltClock Jan 25 '13 at 07:06

2 Answers2

12

The only way I could reproduce the experience you describe is by intentionally creating a port conflict. By default, RavenDB's web server hosts on port 8080, so if you are not changing raven's port, then you must be hosting your WebApi application on port 8080. If this is not the case, please let me know in comments, but I will assume that it is so.

All you need to do to change the port Raven uses is to modify the port value before calling Initialize method.

Add this RavenConfig.cs file to your App_Startup folder:

using Raven.Client;
using Raven.Client.Embedded;

namespace <YourNamespace>
{
    public static class RavenConfig
    {
        public static IDocumentStore DocumentStore { get; private set; }

        public static void Register()
        {
            var store = new EmbeddableDocumentStore
                        {
                            UseEmbeddedHttpServer = true,

                            DataDirectory = @"~\App_Data\RavenDatabase", 
                            // or from connection string if you wish
                        };

            // set whatever port you want raven to use
            store.Configuration.Port = 8079;

            store.Initialize();
            this.DocumentStore = store;
        }

        public static void Cleanup()
        {
            if (DocumentStore == null)
                return;

            DocumentStore.Dispose();
            DocumentStore = null;
        }
    }
}

Then in your Global.asax.cs file, do the following:

protected void Application_Start()
{
    // with your other startup registrations
    RavenConfig.Register();
}

protected void Application_End()
{
    // for a clean shutdown
    RavenConfig.Cleanup();
}
Mohsen Alikhani
  • 1,657
  • 3
  • 19
  • 37
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
2

When you enable the HttpServer in an EmbeddableDocumentStore ravenDB "hijacks" the webapplication and starts listening on the same port that the application is running.

Oren Eini: When you use UseEmbeddedHttpServer from inside IIS, it takes the port from IIS. You need to set the value again

on https://groups.google.com/forum/?fromgroups=#!topic/ravendb/kYVglEoMncw

The only way to prevent it is either turn-ff the raven http-server or assign it to a different port

int ravenPort = 8181;
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort);
var ds = new EmbeddableDocumentStore {
   DataDirectory = [DataFolder],    
   UseEmbeddedHttpServer = true,    
   Configuration = {Port = ravenPort}
};
lboshuizen
  • 2,746
  • 17
  • 20