Monday, May 13, 2013

How to connect to the Oracle database using Business Connectivity Services (BCS) in SharePoint 2010

Introduction:
Business Connectivity Services (BCS) is a new service introduced with SharePoint 2010 to allow SharePoint sites to connect to and manipulate external data. SharePoint 2007 had a similar facility in the form of Business Data Catalog (BDC) which made external data available within its site. However, a major problem with BDC was the difficulty in creating solutions as there was no support in the 2007 designer. Most BDC solutions were simply for accessing external data, manipulating external data sources was extremely difficult.

With SharePoint 2010, BCS ships with out-of-box features such as solutions, services, and tools which may connect to external data an easy task. Whether you want to retrieve Outlook contacts in a list offline or edit the contents of your document file or share your excel sheet online or reuse data from dynamic InfoPath forms or just update your business presentation, BCS enables deep content sharing, editing and integration in SharePoint 2010 with SharePoint Designer and Visual Studio tools. To connect to the SQL database we can use either SharePoint designer (where we can connect directly to the SQL or using WCF or through .Net Assembly) or using Visual Studio (BDC Model). In case of connecting to the Oracle database we don't have direct option in the SharePoint designer, so we can use BCS Meta Man to create an external content type.

Prerequisites:

I. A local installation of either SharePoint Foundation 2010 or SharePoint Server 2010,

ii. Oracle Client (Version: 10g),

iii. Visual Studio 2010 and

iv. BCS Meta Man.

Oracle Database:

Table Name: HR.CUSTOMERS

1.gif

Note:

In the above table CUSTOMER_ID is the Primary Key.

Creating a BCS External Content Type:

Steps Involved:

The following steps should be followed to create a BCS External Content Type using Visual Studio 2010.

v. Open Visual Studio 2010.

vi. Go to File => New => Project.

vii. Select Empty SharePoint Project under installed template category SharePoint 2010 and name it as BCSUsingOracleDatabase.

2.gif

viii. Click OK.

ix. Check "Deploy as a farm solution".

x. Click Finish.

xi. Right click the Solution Explorer and add a New Item.

xii. Select BCSMetaMan under installed template category Lightning Tools and name it as BCSMetaManForOracle.

3.gif

xiii. Click ADD.

xiv. Add System.Data.OracleClient reference to your project.

xv. Connect to the Oracle Database.

  • Go to Tools => Connect to Database.

    4.gif
  • Add Connection wizard will pop up.
  • Choose the Data Source as Oracle Database (Oracle Client).
  • Enter the Server Name, User Name and Password as shown below.

    5.gif
  • Click on Test Connection.

    6.gif

  • Click OK.
  • In the Server Explorer you can view the Oracle Database as shown below.

    7.gif



xvi. Create an External Content Type Using BCS Meta Man.

  • You will find the BCS Meta Man menu item in the menu bar.

    8.gif

  • Click on BCS Meta Man - > BCS Meta Man Data Source Explorer.
  • Click on the "Add Connection" button of the data source explorer.
  • In the Connection Dialog choose the Data Source as Oracle.
  • Enter the Database Name, User Name and Password.
  • Click Connect.

    9.gif

  • Oracle Database will be displayed with all tables.

    10.gif
  • Drag and drop the HR.CUSTOMERS table in the BCS Meta Man design surface.
  • In the Model Type wizard select .Net assembly and click OK.

    11.gif

  • Entity Creation wizard will pop up, click next.

    12.gif
  • By default CUSTOMER_ID will be selected as identifier.

    13.gif

  • Click Next.
  • Select all the methods that are available and click Generate.

    14.gif

  • BCS Meta Man will add new files to the project which contain generated C# code.

    15.gif
  • You'll also see the External Content Type on the design surface as shown below.

    16.gif


xvii. Build the Project.

xviii. Once it is build successfully, Deploy the project.

Configure Business Data Connectivity access rights:

I. Go to Central Administration -> Application Management -> Manage Service Applications.


17.gif

ii. Click on Business Data Connectivity Service.


18.gif

iii. In the top Ribbon click on Manage.

19.gif


iv. In Service Application Information check the External Content Type HR_CUSTOMERS.


20.gif

v. In the top Ribbon click the Site Object Permissions.

vi. Site Object Permissions wizard will pop up add the account (Group or Users) and assign the permissions.

Creating an External List in the SharePoint Site:

I. Open the SharePoint Site.

ii. Go to Site Actions => More Options.

21.gif


iii. On the Create Wizard, from the Installed Templates Select List.

iv. In the List Type select External List and click Create.


22.gif

v. Enter the Name as BCS for OracleDB and choose the External Content Type as shown below.

23.gif

vi. Click OK.

vii. External List is created successfully.

Testing:

Creating a new item:

I. Click on Add new item option in the ribbon.

ii. Enter the values as shown below.


24.gif

iii. Click OK.

iv. New item will be created in the SharePoint External List.


24.1.gif

Update in the Oracle DB:

I. Go to Oracle รข€“ OraClient10g home => Application Management => SQL Plus.

ii. Enter the User Name, Password and Host String as shown below.


25.gif

iii. Select the table to see the changes as shown below.


26.gif

iv. A new item has been added to the HR.CUSTOMERS table.

Summary:

Thus an external content type is created for oracle database using BCS Meta Man and an external list is created based on that external content type to display the Oracle data.

No comments:

Post a Comment