BCS - External Database and Add/Edit/Delete Operations

In this article we can experiment with Business Connectivity Services (BCS) by connecting to an external database. After completing this article you will be able to:

  • View Database Table inside SharePoint
  • Perform Add/Edit/Delete operations

The following are the activities involved:

  1. Create database and table
  2. Using SharePoint Designer create BCS External Content Type
  3. Using SharePoint Designer create Add/Edit/Delete operations metadata
  4. Using SharePoint Designer create Lists & Form
  5. Using Central Administration set Permissions for external Content Type

1. Create database and table

Create a database and table named Customer with the following fields:

BCSShr1.jpg

Add some data into it:

BCSShr2.jpg

2. Using SharePoint Designer create BCS External Content Type

Now we can create an External Content type using the SharePoint Designer. Start the Designer application and open your SharePoint web site > External Content Types as shown below:

BCSShr3.jpg

Click on the External Content Type button from the top side. In the window change the Name and Display Name (click on the links) as shown below:

BCSShr4.jpg

Now click on the External System link and you will get the following dialog:

BCSShr5.jpg

Click on the Add Connection button and select SQL Server in the dialog:

BCSShr6.jpg

In the connection details dialog, enter your server details:

BCSShr7.jpg

Click the OK button and your server connection is ready.

3. Using SharePoint Designer create Add/Edit/Delete operations metadata

From the tables list select the Customer table and right-click to get the context menu. Use the Create All Operations menu item to get the Add/Edit/Delete operations wizard:

BCSShr8.jpg

Click on the Finish button in the wizard:

BCSShr9.jpg

Click on the Save button from the top tool bar:

BCSShr10.jpg

4. Using SharePoint Designer create Lists & Form

Now the operations are ready and we need to create the List Form and the associated Add/Edit/Delete forms inside SharePoint.

BCSShr11.jpg

From the toolbar, click on the Create Lists & Form button as highlighted above. In the dialog box enter the name for the list and click the OK button as shown below:

BCSShr12.jpg

Wait for a while and your List page will be ready:

BCSShr13.jpg

5. Using Central Administration set Permissions for external Content Type

Now you can try viewing the Customer Data list inside SharePoint.

BCSShr14.jpg

On clicking the list, you will be seeing an "Access Denied by Business Data Connectivity" error message. To resolve this we need to set the permission for the External Content Type.

Open the SharePoint Central Administration website. Click on Manage Service Applications:

BCSShr15.jpg

In the page click on the Business Data Connectivity Services link as shown below:

BCSShr16.jpg

In the list, hover over the Customer Data item and click on the Set Permissions menu item as shown below:

BCSShr17.jpg

You will get the following dialog:

BCSShr18.jpg

Enter the user name, click the Add button and check all permissions. Click the OK button to close the wizard. (Make sure you are adding the username used to view SharePoint)
Now you are ready with the Permissions. Go back to the SharePoint > Customer Data list and you will be able to see the data as shown below.

Now you can try playing with the View/Edit/Delete features of the BCS list:

BCSShr19.jpg

References

http://www.zimmergren.net/technical/access-denied-by-business-data-connectivity-solution

Summary

In this article we have seen how to create an External Content Type through Business Connectivity Services and view it inside SharePoint. In the real-world scenario using BCS we can connect to WCF Services and other Business Applications like Microsoft CRM to view/update data inside SharePoint.

Up Next
    Ebook Download
    View all
    Learn
    View all