Click here to Skip to main content
15,890,282 members
Articles / Database Development / SQL Server
Tip/Trick

Write error log in a text file for Custom Assembly being used in Reporting Services

Rate me:
Please Sign up or sign in to vote.
1.44/5 (3 votes)
19 Sep 2013CPOL2 min read 33.9K   14  
writing error in a text file is very easy but writing error from a custom assembly in reporting services requires permissions

Introduction

It is a bit difficult to find an error when using a custom assembly which connects to the database and fetches the values especially when it is running on the client machine. The best solution is to write error messages in a text file. This article shows how can we write errors in a text file using a custom assembly in Reporting Services.

To use a text file from a custom assembly in Reporting Services we will have to give permission to the file in the custom assembly and then we will be able to write errors in this file. Side by side we will have to add permissions in the assemblyinfo file to make the custom assembly DLL accessible from Report Server. Also we will have to add permissions for the DLL in the rssrvpolicy.config file.

I have used Visual Studio to develop a 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. Import "Imports System.Security.Permissions".
  3. Add the following lines in your method to give permission to your text file:
  4. VB
    Dim frp As FileIOPermission = New FileIOPermission(FileIOPermissionAccess.AllAccess, _
                "You Text File path will come here + filename.extension") 
    frp.Assert()
  5. To write error text in this file, use the following code:
  6. VB
    Try 
    ................. Your code  here............. 
    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
  7. You can modify the code according to your requirements. 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 for Reporting Services. The path can be different on your machine so please check it.
  2. Open the file rssrvpolicy.config, the default path is C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer (it can be different on your machine so please check).
  3. Add the following codegroup in this file:
  4. HTML
    <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>
  5. You need to change three things here: Name, Description, and URL.
  6. Name is your DLL custom assembly name.
  7. Description is your DLL description.
  8. URL is your DLL custom assembly path. By default, it is C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\reportHelperLib.dll.
  9. Codegroup should be added at the end of the codegroups section just before ending codegroup tags.
  10. XML
    ..... 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.

Points of Interest

Please do not forget to write comments on how I can improve this article. There may be a few things which I have overlooked and if you will write a comment, I will update my article accordingly and it will be very helpful for other readers. Thanks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --