This project is read-only.

Pulling data from external SQL Server to display on page

Topics: Customizing Orchard, Writing modules
Jul 17, 2015 at 3:53 PM
I'm currently interning at a company over the summer and I'm required to update their employee portal website using Orchard CMS. One issue we have run into is trying to display our phone directory onto a page. Our phone directory is currently located in a separate SQL Server database. All we need is to display the contents of the database in a table on one of our Orchard website pages and have it update whenever a new employee is added, or a number is changed, etc.

My supervisor and I are looking at the best course of action for completing this. Is there a module already created for connecting to an external database and pulling data from it? Will we have to create our own module that can accomplish this task? If so, would you suggest creating our own "Phone Directory" widget, or creating a phone directory content part, or something completely different.

I apologize if I sound like a beginner because I am. I have little experience in extending Orchard and C# programming in general. We're just having trouble discovering where the extension points are for a module like this would be. If one of the developers or anyone could provide some insight and/or documentation or tutorials on how to extend Orchard in the way we need to accomplish our task, it would be greatly appreciated.

Jul 18, 2015 at 11:58 PM
Edited Jul 18, 2015 at 11:59 PM
There's probably no generic module out there that lets you connect to an external database, so you'll have to create your own module to accomplish that.
Without knowing exactly how you intend to use this data, you'll probably get the most out of it by implementing a custom content part. This part can then be attached to any content type (including custom widgets, which are also just content types but with the WidgetPart attached and its Stereotype set to "Widget"). In the form of a widget you can put it in any zone you like.

If you're looking to create custom widgets, I'd start with the documentation, which demonstrates how to write a custom Maps widget.
There are also two great courses on Pluralsight that are highly recommended. Even though they are becoming a bit outdated, many principles shown there still apply and are good knowledge to have.
And if you're looking for a nice and long hands on tutorial, check out my blog post series on writing a custom webshop module.

Good luck!
Jul 20, 2015 at 1:02 PM
Thank you for the response!

We don't intend on "using" the data, but rather just display it on a page for reference in a tabular format. How easy/hard would it be to connect to a database and just load the data onto a page? Currently my plan is to make a custom content part and have it attached to a widget - like you said. Is it possible to make a table from the data, though?

I appreciate the tutorial resources you provided. I'll be sure to check them out. Thanks for the assistance!
Jul 20, 2015 at 5:32 PM
You're welcome.

It would be very easy to display your data in a tabular format, or in any way you like, since you have complete control over the rendering of this data. The way this works is that from your custom content part driver you return a shape, which is rendered using a Razor view file that you create. When you create your shape you will set your data onto that shape so that's accessible from the Razor template, from which you will access this data and render it.
Jul 23, 2015 at 10:31 AM
Edited Jul 23, 2015 at 10:31 AM
The Custom webshop module looks awesome, may I know if the process of creating it is still applicable in the 1.9 version of Ochard?
Jul 24, 2015 at 12:49 PM
Thank you. :)

Yeah some parts I'd write differently, like taking advantage of InfoSet and newer features, but all in all I think it still serves as a good introduction to Orchard module development.