Everyone who uses Sharepoint sites, will be using database access for displaying data in your Sharepoint sites. The accessing of Database is made easier by the Microsoft Enterprise Library Application blocks. But unfortunately the Application Block DLLs cannot be directly used in our sharepoint sites. The MSEL DLLs may work fine in an ordinary ASP.NET web application scenario but when one wants to make this ASP.NET application into a Sharepoint application, we need to do some tweaks and this article is written for that purpose.
The MSEL Application Block DLLs are not strong named when it comes with the package. This is for various reasons. But when we wnat to use it in our Sharepoint site, then it has to be Strong named. Also the DLLs that have to be used in the Sharepoint site must be compiled with Partially trusted so that any page in your application can use this in your Sharepoint site.
Microsoft Enterprise Library Application Block (MSEL): January 2006 with Patch 2554
SharePoint: SharePoint Server 2007
Visual Studio: Visual Studio 2005
MSEL January 2006 Download link: http://www.microsoft.com/downloads/details.aspx?FamilyID=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en
Patch 2554 for MSEL download link: http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=1339
MSEL must be Installed and the Application blocks compiled (This is a step during installation of MSEL).
The first step is to compile and create signed Enterprise Library DLLs. For that we need to do the following
- Compiling the Enterprise Library Application blocks
- Extract the Patch 2554 for MSEL Application Block.
- Copy the Src and UnitTests folders, which are included in the patch archive file, over the existing Src and UnitTests file installed with Enterprise Library. (By default, the Enterprise Library is located at C:\Program Files\Microsoft Enterprise Library January 2006). Applying the patch will overwrite a number of existing source files with new versions that are supplied with the patch.
- Open the EnterpriseLibrary solution (EnterpriseLibrary.sln – By default, located at C:\Program Files\Microsoft Enterprise Library January 2006).
The solution will contain project code for all the application blocks as shown below
5. Here, you will have to do the following for the Application block DLLs that you will be using in your project.
6. First, you have to strong name the DLL.
Steps for Strong Naming a DLL
a. Create a strong name key by using the sn –k sample.snk command
b. Right Click on the Class library project that you want to strong name and click Properties
c. Go to the Signing tab
d. Check the 'Sign the Assembly' option
e. Choose Browse option from the below dropdown as shown in below figure
f. A 'Select File' dialog box will appear. Go to the location where you have saved the strong name key and select the key.
g. Now Click on the Save button to save the setting.
7. Second step is to make the DLL Allow Partially Trusted.
8. Open the AssemblyInfo of the Project that you have strong named in the previous step.
9. Add the below line in the AssemblyInfo file as shown above and Save the file
10. Now Compile the project individually.
11. Go to the output folder of the project and take the DLL. This DLL is the one that is required to be used in the SharePoint site.
Now that we have got the Enterprise library DLL, then next step is to add the application block and the references to the SharePoint site. For this we need to do the following.
(Note: For this article, we add the DataAccess Application Block)
Adding Application Blocks into SharePoint site
1. Open your SharePoint site web.config (Usually in
2. Add the following in the <configSections> section Add the following in the <configSections> section
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" requirePermission="false" />
3. Add the following section right after the <ConfigSections> section
<dataConfiguration defaultDatabase="SampleDatabaseName" />
4. Add another section right after the previous section
<connectionStrings> <add name="SampleDatabaseName" connectionString="Data Source=<DataServerName>;Initial Catalog=<DatabaseName>;user=<DatabaseUserName>;pwd=<DatabasePassword>;Persist Security Info=true;" providerName="System.Data.SqlClient" /> </connectionStrings>
5. Put the Enterprise Library DLLs that your SharePoint site uses in the bin folder which is in the same location as your web.config file
6. Make the DLLs that you have added as Safe Controls by adding them in the <SafeControls> section
<SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Common" Namespace="Microsoft.Practices.EnterpriseLibrary.Common" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Data" Namespace="Microsoft.Practices.EnterpriseLibrary.Data" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.Practices.ObjectBuilder" Namespace="Microsoft.Practices.ObjectBuilder" TypeName="*" Safe="True" />
(The above DLLs are added for the Data Application block DLLs)
7. Change the level in the <trust> node to WSS_Medium
<trust level="WSS_Medium" originUrl="" />
8. Also add/uncomment the following line in the <PageParserPaths> section
<PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
Now your SharePoint site is ready to use the Data Access Application Block of Microsoft Enterprise Library.
Note: You now use the Enterprise Library Configuration tool to add other application blocks.