Introduction
It is really very difficult to find the error / problem with custom assembly which connects to the database and fetch values especially when it is running on the client machine. Thy solution can be writing errors in a text file. This article shows how can we write errors in a text file using custom assembly in reporting services.
To use text file from custom assembly in reporting services we will have to give permission to this file in custom assembly and then we will be able to write errors into this file. Side by side we will have to add permissions in the assemblyinfo file to make custom assembly dll accessible from report server. Also we will have to add permission for our dll in rssrvpolicy.config file.
I have used visual studio 2003 to develop class library (custom assembly) using vb.net.
Using the code
Steps for Assemblyinfo.vb
1. Add <Assembly: AllowPartiallyTrustedCallers()> in assemblyinfo.vb file
2. Import "Imports System.Security"
Steps for Class file in Class library (custom assembly)
1. Import "Imports System.IO"
2. And import "Imports System.Security.Permissions"
3. Add following lines in your method to give permission to your text file
Dim frp As FileIOPermission = New FileIOPermission(FileIOPermissionAccess.AllAccess, "You Text File path will come here + filename.extension")
frp.Assert()
4. To write error in this file use following code
Try
................. some of you code.............
Catch ex As Exception
Dim sw1 As StreamWriter = New StreamWriter(getPath("FestivalBSLogFile.txt"), True)
sw1.WriteLine(DateTime.Now.ToShortDateString & " " & DateTime.Now.ToLongTimeString & ": " & ex.Message)
sw1.Flush()
sw1.Close()
End Try
5. You can modify your code according to you requirement. This is a very simple example just to make sure it is working.
Steps for Deployment on Report Server
1. Copy custom assembly (class library) DLL in the C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\reportHelperLib.dll folder. This is a default folder of reporting services. Please make sure the path of reporting services on your machine.
2. Open the file rssrvpolicy.config, default path is C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer
3. Very carefully add following codegroup in this file.
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="reportHelperLibSample"
Description="reportHelperLib. ">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\reportHelperLib.dll"
/>
</CodeGroup>
4. You need to change three things here Name, Descriptioni and Url.
5. Name is your DLL custom assembly name
6. Description is your dll description. It can be any
7. Url is your DLL custom assembly path. By default it is C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\reportHelperLib.dll
8. There are few tips to add this codegroup because this is very important part to make our dll run.
9. First tip, add your codegroup at the end of codegroups section.
10. Second tip your codegroup should be copied before two ending codegroup tags
..... here.....
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
11. Restart report server from control panel>Administrator>Services>report server
12. If restarting is not working then restart your computer.
Ali Faraz
Software Developer
Festival Business Solutions
United Kingdom
Points of Interest
Please do not forget to write comments that how can i improve this article. There may have few things which i have overlook and if you will write comment, i will update my article accordingly and it will be very helpful for other readers. Thanks.