This project is read-only.

How to use multi database in Orchard?

Jan 18, 2011 at 3:18 PM
Edited Jan 18, 2011 at 3:27 PM

Hi everyone, i'd like to connect to another database within orchard. How can I build a new NHibernate SessionFactory? Thanks in advance.

Jan 18, 2011 at 7:51 PM
Edited Jan 18, 2011 at 7:51 PM

Can you give more details about what you're trying to do? Are you trying to create another database engine provider for Orchard or to connect existing external data to Orchard?

Mar 15, 2012 at 3:20 PM

I have installed and run Orchard using SQLCe. But I need to connect to another database on MSSQL 2008 server to get data parallel.

Could you give me some example code to connect to db using Entity Framework is the best.

(I used to use Entity Framework on other MVC 3 projects)

Thank in advance.

Mar 15, 2012 at 4:13 PM

Can't you just new up an EF Object Context and use it, just like in other MVC 3 projects?

Mar 16, 2012 at 10:02 AM
Edited Mar 16, 2012 at 10:44 AM

I have try...

My module is [MyModule]

Step 1: add new ADO.NET Entity Data Model name [StoreDB.edmx] (Generate from database) in MyModule/Models; everything work same ok

Step 2: In my controller

// Note: [dgnd] is my database name, [dgndEntities] is my entity object class name

public void ImportData()
            dgndEntities storeDB = new dgndEntities();

         // Try to count total records in table Properties

            ViewBag.PCount = storeDB.Properties.Count();


Step 3: on frontend

Compiler Error Message: CS0246: The type or namespace name 'dgndEntities' could not be found (are you missing a using directive or an assembly reference?)


I search for a solution, and add this to root/Web.config


<add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Then new error:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.


I check Solution Explorer and see that there is App.Config file in my module folder [MyModule] contain connectionStrings


    <add name="dgndEntities" connectionString="metadata=res://*/Models.StoreDB.csdl|res://*/Models.StoreDB.ssdl|res://*/Models.StoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[server];initial catalog=dgnd;persist security info=True;user id=[username];password=[password];multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

If I copy <connectionStrings> to root/Web.config, new error:

Unable to load the specified metadata resource.


Could anyone help me to solve this problem?

Thank in advance.

Mar 17, 2012 at 9:26 PM

It doesn't seem to have anything to do with Orchard, and everything to do with EF.