Introduction
In this tutorial we will show you how to connect to a Microsoft SQL Server database using BCS Meta Man and a Stored Procedure to return filtered data to a SharePoint Business Data List. In this walkthrough we will be creating a Finder Method with filters so our Stored Procedure needs to have parameters defined.
Prerequisites
- SharePoint Foundation 2010 or SharePoint Server 2010
- Visual Studio Professional or higher
- BCS Meta Man
- AdventureWorks SQL Database
- A SQL Stored Procedure with parameters such as
USE [AdventureWorks] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Lightning Tools Ltd -- Create date: 07/16/2010 -- Description: Sample Stored Procedure to return filtered Customer information -- ============================================= CREATE PROCEDURE [dbo].[uspGetCustomerFiltered] -- Add the parameters for the stored procedure here @FirstName nvarchar(50) = null, @LastName nvarchar(50) = null AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT CustomerID, Title, FirstName, LastName, EmailAddress from SalesLT.Customer where FirstName = IsNull(@FirstName,FirstName) and LastName = IsNull(@LastName,LastName) END GO
Walkthrough
- Open Visual Studio 2010
- Add a New Project
- Select the ‘SharePoint 2010’ node, and then the ‘Empty SharePoint Project’ project type
- Give your project a name i.e BCSMetaManFilteredStoredProcedure
- Click ‘OK’
- On the next dialog box, enter the name of where you want to deploy your model, and make sure you select ‘Deploy as a farm solution’ , click ‘Finish’
- Add a new item to the newly created Project, either right-click on the Project in the Solution Explorer and Navigate to Add New Item, or select the Project Item and press ‘Ctrl+Shift+A’
- Select the ‘Lightning Tools’ node, select ‘BCSMetaMan’ Item Type, give your model a name, such as ‘CustomerModel’ and click ‘Add’
- If prompted, click Trial on the licensing dialog
- To show the ‘BCS Meta Man Data Source Explorer’ we need to enable it from the Menu item, this new window can be docked so it doesn’t get in your way.
- Click the ‘Add Connection’ button to show the ‘Connection Dialog’
- Select the Data Source type, enter your Server name and also select whether to ‘Use Windows Authentication’ or you provide logon credentials, click ‘Connect’
- The Data Source Explorer will now be populated with your Server databases
- Expand your Database and find the Finder Method Stored Procedure
- Drag the Stored Procedure onto the main Diagram
- Select ‘Database’ as the Model Type and click ‘OK’
- You will be prompted for a name of the External Content Type being created
- Select the Method Type as ‘Finder’’
- Select the first Parameter (FirstName) and set it’s Filter Type to Comparison and the Default Value to ‘*’
- Next select the second Parameter (LastName) and also set it’s Filter Type to Comparison and the Default Value to ‘*’
- Click ‘OK’
- The External Content Type will be created on the Diagram
- Press F5 to deploy, this will load up your SharePoint Page once deployed
- Add a new Business Data List Web Part to your SharePoint page
- Click on the ‘Open the tool pane’ link
- Click on the icon to show the available External Content Types
- Select our ‘BCSMetaManFilteredStoredProcedure.Customer’ External Content Type, click ‘OK’
- Click ‘OK’ on the tool pane
- Click the ‘Add’ link on the Business Data List Web Part to add the second Filter option
[Click to view a larger image]
- Change the second Filter to be the LastName and enter values for the filters and click ‘Retrieve Data’
- Your External System data is now displayed in the SharePoint Web Part
<phill/>