Connecting with external sql server in Umbraco 7 MVC
Hello, I am newby with Umbraco and it has been hard for me to get updated info about how to connect with external database and render non-umbraco info into my umbraco views.
May I use a secondary connectionstring and ApplicationContex?
Or make another MVC project in the same solution and share the DLL?
Or must use web services to do that?
There are several answers to your question. You can solve this issue in a way that feels most comfortable to you.
You can add a connection string and read your data using SQL queries or using ORM like NHibernate, Entity Framework or PetaPoco (which ships with Umbraco).
Or you can create a seperate webservice or WebApi application that you consume from Umbraco.
In this code I created for a DUUG presentation is an example of getting data from a custom table (in this case is in the same database) using PetaPoco and exposed as through WebAPI.
Glad to see it helped you further. Strange that you needed to download the 7.1.6 binary files by the way. I believe I enabled nuget package restore in the solution.
I'm facing the same challenge as Karl now, I want to be able to show data from an external database in an Umbraco partial view. I have followed this receipe for showing data from custom tables in the same database as Umbraco (in my case Umbraco.mdb) using PetaPoco, and this works fine. However, I now want to access data in a different database, assuming I can use the same Technology (PetaPoco).
So the question is: how do I connect the models and controllers to a different database than the Umbraco database? Where goes the secondary database connection string and where do I refer to it? From what I understand, this was what you were trying to do, Karl?
Connecting with external sql server in Umbraco 7 MVC
Hello, I am newby with Umbraco and it has been hard for me to get updated info about how to connect with external database and render non-umbraco info into my umbraco views.
May I use a secondary connectionstring and ApplicationContex? Or make another MVC project in the same solution and share the DLL? Or must use web services to do that?
How do I approach to this need?
Thx, Karl
Hi Karl,
Welcome to our.
There are several answers to your question. You can solve this issue in a way that feels most comfortable to you.
You can add a connection string and read your data using SQL queries or using ORM like NHibernate, Entity Framework or PetaPoco (which ships with Umbraco).
Or you can create a seperate webservice or WebApi application that you consume from Umbraco.
In the views you can load the data.
Dave
Thanks Dave,
Could yo refer me to a sample with a secondary SQL connection string and retrieve data from Models to Umbraco Partial View?
Karl
Hi Karl,
In this code I created for a DUUG presentation is an example of getting data from a custom table (in this case is in the same database) using PetaPoco and exposed as through WebAPI.
You can use these models in your views.
Maybe it is a good starting point ?
Code can be found here : https://bitbucket.org/dawoe/duugcustomsections
Dave
Dave, I have need some time to make it work, but now I can use your sample and it looks great!
These are the steps I did, it will be useful for future readers of this post. It has been also a way to learn Umbraco installation
Thanks for your support Karl
Glad to see it helped you further. Strange that you needed to download the 7.1.6 binary files by the way. I believe I enabled nuget package restore in the solution.
Dave
Hi Karl and David,
I'm facing the same challenge as Karl now, I want to be able to show data from an external database in an Umbraco partial view. I have followed this receipe for showing data from custom tables in the same database as Umbraco (in my case Umbraco.mdb) using PetaPoco, and this works fine. However, I now want to access data in a different database, assuming I can use the same Technology (PetaPoco).
So the question is: how do I connect the models and controllers to a different database than the Umbraco database? Where goes the secondary database connection string and where do I refer to it? From what I understand, this was what you were trying to do, Karl?
Best, Bendik
Just add your connnection string in web.config, you can have as many connections as you want.
Thanks Dirk!
Yes, I figured this out, and I also figured out how to use it with PetaPoco: In your XyzRepository class:
Instead of
you use
Simple as that! I also figured out the connection string to an MS Access database, in case anyone is interested:
is working on a reply...