Click here to Skip to main content
Licence 
First Posted 15 Jun 2007
Views 20,082
Bookmarked 12 times

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

By | 15 Jun 2007 | Article
writing error in a text file is very easy but writing error from a custom assembly in reporting services requires permissions
 
Part of The SQL Zone sponsored by
See Also

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

alifaraze

Web Developer

United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 15 Jun 2007
Article Copyright 2007 by alifaraze
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid