BDC Models in Visual Studio 2010 for SharePoint Foundation Server 2010

Posted by Troy on August 7, 2010 under Microsoft, SQL Server, SharePoint, Visual Studio, Web, csharp | Be the First to Comment

When I first started building External Content Types in (ECT) SharePoint Foundation Server I used SharePoint Designer.   SharePoint Designer is a good place to start if you are learning how build ECT’s.  It does not require any .NET code and you can build a fairly decent application in little time especially if you have a solid relational database background.  But I wanted to try build an External Content Type using Visual Studio 2010.   In this case I am going to build a simple BDS Model based on the SalesLT.Customer table in the AdventureWorksLT2008R2 database.

First, lets start by creating an empty SharePoint 2010 Solution (C#)  in Visual Studio 2010.  Select File > New > Project from the file menu.  In the Installed Template section under Visual C# > SharePoint > 2010 select the Empty SharePoint Project and name the project SPDev1.  This will create an empty SharePoint project which we can add multiple projects to.

image

When you select Ok the SharePoint Customization will be displayed.  Enter the the site you want to use for debugging the project and make sure you select “Deploy as a farm” solution:

image

Right-click on the SPDev1 project and select Add New Item:

image

Now Select Business Data Connectivity Model from the Add New Item list and name it AWLTCustomer.  Once you enter the name of the model click Add:

image image
Add BDC Item BDC Solution

When the BDC Model is added it is fully functional.  If you Build the project it will compile without any errors. 

You will notice that I named the Blog Post “BDC Models in Visual Studio 2010 for SharePoint Foundation Server 2010”  and not “BDC Models in Visual Studio 2010 for SharePoint Server 2010”  .  If you created this project using SharePoint Server 2010 you can actually deploy this project to the debug site and it will create an BDC Model with an entity called Entity1.  But if you are using SharePoint Foundation Server 2010 you will receive the following error when the project is deployed (Right-click the project and click Deploy):

Error    1    Error occurred in deployment step ‘Add Solution’: Failed to load receiver assembly "Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" for feature "SPDev1_Feature1" (ID: 1a75169a-e716-4d4b-a43c-3c0cf032fc40).: System.IO.FileNotFoundException: …

In order to deploy a BDC Model to Foundation Server a Feature Event Receiver is required to publish the mode to the site:

Publish BDC Model project to SharePoint Foundation 2010 with Visual Studio 2010

The following post on one of the Microsoft Blog sites provides details on how create the Feature Event Receiver. 

Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010

Basically you need to download the following file from the first link:

Feature Event Receiver (C#) 

In the current project, add an Event Receiver to Feature1 by right-clicking Feature1 and select Add Event Receiver:

image 

First copy the existing content of Feature1.EventReceiver.cs to a file using notepad.  Next, replace the contents of Feature1.EventReceiver.cs with the contents of the file downloaded from the Microsoft site (FeatureEventReceiver.cs) (Ctrl-C, Ctrl-V).   The details from this point on can be found in the Microsoft Blog post mentioned above (Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010), but I will provide some additional screenshots along with the steps.

We need to Add a reference to the MicrosoftBusinessData.dll. In order to do this you have to copy the dll from the GAC.    Click Start > Run and enter the following:

  • C:\Windows\assembly\gac_msil
image image

 

Find the Microsoft.BusinessData folder and copy the Microsoft.BusinessData.dll to the following folder:

  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

Next add the following references to the project:

image image
System.Web Microsoft.BusinessData.dll

Set the BDC (SharePoint item property) which in our case is located in the AWLTCustomer model and set the following properties located under Feature Receiver Category:

  • Assembly = Assembly = $SharePoint.Project.AssemblyFullName$
  • Class Name = SPDev1.Features.Feature1.ImportModelReceiver
image image
Properties Before Properties After

Set the Feature property by double clicking on Feature1.Feature and update the following property:

  • Receiver Class = SPDev1.Features.Feature1.ImportModelReceiver
image image
Properties Before Properties After

One last thing, we need to change the Namespace of the code that was copied into Feature1.EventReceiver.cs from BDCModelReceiver to SPDev1:

image 

I have been writing this post while following  Microsoft Blog.  So, here is the moment of truth.  After the last step we should be able to deploy the BDC model.  Right-click on the project and click deploy or click F5 if you want to debug the solution.  To view the content type you can open SharePoint Designer and navigate to the External Content Type sit object:

image

Before you can create an External list based on the new External Content Type the permissions must be set.  Check out this post for setting the permissions using the SharePoint Central Administration site:

Setting Permissions for an External Content Type

Once the permissions have been set an External List can be created.  In this example the External List is very basic and in fact the model has not been connected to the External table in the Adventure Works.   But that is a topic for another post.

For more information on BCS check the Microsoft BCS Team Blog:

http://blogs.msdn.com/b/bcs/

 

Troy

Cannot start service SPUserCodeV4 on computer

Posted by Troy on August 6, 2010 under .net, IT, Microsoft, SharePoint, Visual Studio, Web | Be the First to Comment

This week I was creating my first SharePoint 2010 Sandboxed solution using Visual Studio 2010.  I have successfully built and deployed other SharePoint projects on the server but I always used Farm based solution due to the requirements.

When I built the Sandboxed solution the project would build and package without any errors but when I tried to deploy it to the SharePoint site the following error occurred:

Error    1    Error occurred in deployment step ‘Activate Features’: Cannot start service SPUserCodeV4 on computer ‘SERVERNAME’ 0    0    SP2010Dev1

The error can be easily resolved by starting the Microsoft SharePoint Foundation Sandboxed Code Service which can be accessed through the Central Administration site in SharePoint.   Open the Central Administration site and go to System Settings and click on Manage Service on server:

image

Check to see if Microsoft SharePoint Foundation Sandboxed Code Service  is running, it should be stopped :

image

Start the service and try deploying the Sandboxed solution.

Thanks to Sergey Hyper Kravchenko for his post on the MSDN SharePoint discussion forum:

error occurred in deployment step ‘retract solution’ cannot start service SPUserCodeV4 on this computer

Troy

Running Eclipse Helios on Windows 7 (64 bit)

Posted by Troy on July 4, 2010 under Eclipse, IT, Open Source, Web | Be the First to Comment

 

If you have installed Eclipse Helios (64-bit) on Windows 7 (64-bit), make sure the correct version of java (64-bit) is installed on the computer:

http://www.java.com/en/download/manual.jsp

If you have java installed and you get the error shown below when you try to run Eclipse chances are you have the 32-bit version of Java installed:

"Failed to load the JNI shared library "C:\Program Files(x86)…”

Thanks to this post from the Eclipse Community Forums

http://www.eclipse.org/forums/index.php?t=msg&goto=542940&#msg_542940

 

Troy

Building BI Application’s with SharePoint 2010

Posted by Troy on July 1, 2010 under Business Intelligence, IT, Microsoft, SharePoint, Web | Be the First to Comment

 

SharePoint 2010 is an excellent Platform for creating enterprise applications that leverage your current Business Intelligence infrastructure and operational systems.  Of course your not going to build mission critical applications like POS or Supply Chain Ordering system but what about tracking weekly sales and expenses or building a pricing model that requires data from multiple data sources.    Using a combination of SharePoint 2010 and the Office 2010 products it is possible to create robust enterprise applications with a reasonable amount of effort.

Business Connectivity Services (BCS) in SharePoint 2010 and SharePoint Designer 2010 is what makes these applications possible.  Sure you could build your application using native SharePoint list but this approach is limited and does not allow you to leverage existing systems like your corporate data warehouse.    Below is a simple diagram which show how BCS allows business user’s to access external data:

image

The best way to learn about how these tools work is to work through a practical example.    Over the next few blog posts I will walk through how to create a simple sales forecasting application.   I am assuming that you have access to a desktop machine or server with at least the following software:

  • SQL Server Express 2008 R2
    • Adventure Works DW R2
  • SharePoint 2010 Foundation Server
  • SharePoint 2010 Designer

In this scenario the business users want to create a weekly forecasting model which will forecast Internet Sales by Territory by Product Category.  Execute the following to create a forecasting table in the Adventure Works DW R2 database:

select fcst.* into dbo.WeeklySalesForecast from ( select dt.CalendarYear,'Week ' + convert(nvarchar(2),dt.WeekNumberOfYear) WeekNumber , dt.MonthNumberOfYear, dt.EnglishMonthName, ter.SalesTerritoryGroup, ter.SalesTerritoryRegion, cat.EnglishProductCategoryName Category, sum(fct.OrderQuantity) LastYearQuantity, sum(fct.SalesAmount) LastYearAmount, null ForecastQuantity, null ForecastAmount from dbo.FactInternetSales fct inner join dbo.DimDate dt on fct.OrderDateKey = dt.DateKey inner join dbo.DimProduct prd on fct.ProductKey = prd.ProductKey inner join dbo.DimSalesTerritory ter on fct.SalesTerritoryKey = ter.SalesTerritoryKey inner join dbo.DimProductSubcategory sub on prd.ProductSubcategoryKey = sub.ProductSubcategoryKey inner join dbo.DimProductCategory cat on sub.ProductCategoryKey = cat.ProductCategoryKey where dt.CalendarYear = 2008 group by dt.CalendarYear,dt.WeekNumberOfYear, dt.MonthNumberOfYear, dt.EnglishMonthName, ter.SalesTerritoryGroup, ter.SalesTerritoryRegion, cat.EnglishProductCategoryName) fcst

This will create a table that can be used for building the BCS.   In this post we are going to simply create a SharePoint site using SharePoint Designer to host our SharePoint application using SharePoint Designer 2010.   Open SharePoint Designer 2010 and open the Main Site.  In my case my main site is on my laptop and can be accessed at http://localhost.  From the Site Actions menu select “New Site”:

image

 

We are now going to create a new Site called Ops Forecast (http://localhost/opsforecast) use the Team Site template:

  • Title: Ops Forecast
  • Url Name:  opsforecast

image

Now click Create and the site will be created.  In the next post we will build 2 stored procedures and create an External Content Type which will be used as a list to view the forecast data in SharePoint.

 

Troy

SharePoint Master Page missing from Look and Feel

Posted by Troy on June 7, 2010 under Microsoft, SharePoint, Web | Be the First to Comment

In order to see the Master Page menu option in the “Look and Feel” Sites Settings section in SharePoint 2010, you have to activate the SharePoint Server Publishing Infrastructure.  There are two features that need to be activated in SharePoint

  • SharePoint Server Publishing Infrastructure
  • SharePoint Server Publishing

These features must be activated at the web site level and not by using the Central Administration Web Application.  This can cause some confusion because these settings are available in the Central Administration tool.

First, navigate to the website that where you want to activate the Publishing feature.  Next,  Select: Site Actions>Site Settings

sharepoint_publishing_1

Now Select, Site Collection Features from the Site Collection Administration section:

sharepoint_publishing_2

In this section you want to activate the SharePoint Server Publishing Infrastructure

sharepoint_publishing_3

Go back to the Site Settings page and select Manage Site Features from the Site Actions section.   This time you need to activate SharePoint Server Publishing

sharepoint_publishing_4

Once this is activated the Master Page option will be available in the Look and Feel section for the Site Settings:

sharepoint_publishing_5

Its important to remember that this must be set up at the site level.

Troy