Tuesday, September 20, 2011

Setting up Business Connectivity Services in SharePoint 2010

The Business Connectivity Services (BCS) are a set of services which are used to connect to external data such as a SQL Server database. In combination with SharePoint designer, it is fairly easy to create external content types and lists (creating it in Visual Studio is also a possibility but more difficult to do). Personally, I had a little bit of difficulty setting it up the whole thing. The first thing I tried to do was to create an external content type for an arbitrary table in SQL Server, but I got the following error in SharePoint Designer: "The Business Data Connectivity Metadata Store is currently unavailable."

Other SP peers seemed to have the same problem and many could solve it by installing a WCF hotfix (KB976462), however this did not work for me. I will show you three checks I did in order to have stuff working. 1. Check if the Business Data Connectivity Service is running. You can find it by going to "Central Administration" -> "Manage services on server". If it has stopped, start it again.

2. Make sure you've got a Business Data Connectivity Service Application set up in "Application Management" ->"Service Applications"->"Manage service applications"

3. The next one is what I overlooked and made me waste hours of my life. Go to "Application Management"->"Service Applications"->"Configure service applications associations". In here you need to check whether your BCS Application Proxy is checked, otherwise it won't work.

Monday, September 19, 2011

Appliance of Strategy Design Pattern

Here is a small example of how I used the Strategy Design Pattern to re-use specific methods
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Appliance of the Strategy Pattern

namespace ConsoleApplication5
{
        class Program
        {
            static void Main(string[] args)
            {
                Dude Earl = new Dude("Albert");
                Dude Gary = new Dude("Gary");
            
                Earl.SetMorningRitual(new CigaretteSmoker());
                Gary.SetMorningRitual(new CoffeeDrinker());

                Earl.WakeUp();
                Gary.WakeUp();
            
                // During the day Earl decides to give up smoking and start drinking coffee in the morning instead.

                Earl.SetMorningRitual(new CoffeeDrinker());
                Earl.WakeUp();
                Console.ReadKey();

            }
        }

        class Dude
        {
            IMorningRitual _behaviour;
            String _name;

            public Dude(String MyName)
            {
                _name = MyName;
            }

            public void SetMorningRitual(IMorningRitual Behaviour)
            {
                _behaviour = Behaviour;
            }

            public void WakeUp()
            {
                Console.WriteLine(this._name + " just woke up");
                _behaviour.DoMorningRitual();
            }
        }

        public interface IMorningRitual
        {
            void DoMorningRitual();
        }

        public class CigaretteSmoker : IMorningRitual
        {
            public void DoMorningRitual()
            {
                Console.WriteLine("Still sleepy but gonna smoke one anyway.. *lights cigarette\n");
            }
        }

        public class CoffeeDrinker : IMorningRitual
        {
            public void DoMorningRitual()
            {
                Console.WriteLine("A morning without coffee is like something without something. Aahhh delicious!\n");
            }
        }

}