SQL Server 2000 Reporting Services: How to display localized information according to user language preferences

xiaoxiao2021-03-06  41

Since the release of Microsoft's Reporting Servcies, due to its simple, powerful, more and more users choose to do it as a report solution. Under the big trend of today's internationalization, many users will encounter a problem when using Reporting Servcies, which is how to display localized information according to the user's language preference, such as the Chinese user display Chinese report title, for the United States The user displays the title of English in English; there is also a different currency symbol like a user of different countries. This article provides two ways to solve this problem.

Method 1:

Let's suppose you want to display column name for Different Users (for example,

For Chinese users, Display "Name"; For Other Users, Display "Name", YOU MY USE

Expressions to Do So as Follows:

= IIF (user! Language = "zh-cn", "name", "name")

User! Language is a global variable in reporting services Which Will Return THE

User's Language, For English Users, IT Will Return "EN-US"; for Chinese users, IT

Will Return "en-cn".

For More Information Regarding User! Language, please refer to msdn.

Method 2:

A More Flexible But Complex Way to Do So Is To Use Custom Assembly in your report.

That IS, Store The Localized String In External Storage Such As SQL Server Database or XML Files, Then Write a Custom Assembly To Retrieve The Localized String from THE

External Storage Based on User's Language, and The Call this assembly in your report. The detaild steps are:

Create a Table to Store The Localized String:

Use northwind

Go

Create Table LocalizationTBL (SourceStr NVARCHAR (20), Language Nvarchar (10), DESTSTR

NVARCHAR (20))

Go

INSERT INTO LOCALIZATIONTBL VALUES (N'Name ', N'ZH-CN', N 'Name ")

INSERT INTO LOCALIZATIONTBL VALUES (N'Name ', N'En-US', N'Name ')

Go

2. Create The Custom Assembly. Launch Visual Studio .NET 2003, Create a Class Library Project, And Add A Static Method To Retrieve The Localized String from The Database:

Using system;

Using system.data;

Using system.data.sqlclient; using system.security;

Using system.security.permissions;

Namespace getLocalstring

{

Public Class Class1

{

Public Static String getLocalizedString (String Language,

String SourceStr)

{

SqlclientPermission permission = new

SQLClientPermission (System.Security.Permissions.Permissionstate.unRestricted);

Permission.assert ();

SqlConnection conn = new sqlConnection ();

Conn.Connectionstring = @ "server =

ServerName; Database = northwind; uid = sa; pwd = xxxx; ";

SQLCommand cmd = new sqlcommand ();

cmd.commandtext = "SELECT DESTSTSTR

LocalizationTBL where language = '" language "' and sourceStr = '" SourceStr

"'";

cmd.commandtype = commandtype.text;

cmd.connection = conn;

Cn.open ();

Return cmd.executescalar (). TOSTRING ();

}

}

}

3. Build the project, and then deploy the DLL file to Reporting Services. To deploy the DLL file, copy it from your build location to the report server bin folder and the Report Designer folder. The default location of the bin folder for the report server is C: / Program Files / Microsoft SQL Server / MSSQL / Reporting Services / ReportServer / bin The default location of the Report Designer is C:. / Program Files / Microsoft SQL Server / 80 / Tools / Report Designer.

4. By Default, The Custom Assembly Doesn't Have Permission to Run in Reporting

Services, you need to modify the configuration files of Report Designer and report server to grant it the FullTrust Permission The configuration file for report server is C:. / Program Files / Microsoft SQL Server / MSSQL / Reporting Services / ReportServer / rssrvpolicy.config. The configuration file of report designer is C:. / Program Files / Microsoft SQL Server / 80 / Tools / Report Designer / rspreviewpolicy.config You need to add a code group for your custom assembly similar as follows (please modify the value for the URL Attribute based on your dll file name):

Version = "1"

PermissionssetName = "fulltrust"

Name = "localized_string"

Description = "">

Version = "1"

URL = "File: // C: / Program Files / Microsoft SQL

Server / MSSQL / Reporting Services / ReportServer / Bin / GetLocalstring.dll "/>

For more information regarding code access security for Reporting Services, please refer to a comprehensive white paper http://msdn.microsoft.com/library/en-us/dnsql2k/html/dngrfCodeAccessSecurityInSQLServer2000ReportingServices.asp

5. Add assembly reference to the report To add an assembly reference to a report, on the Report menu, click Report Properties On the References tab, do the following:.. In References, click the add (...) button and then Select or browse to the assembly from the add. Dialog box.

6. THEN you may use expression in the report to call the static method defined in the assembly as stock:

= getLocalstring.class1.getlocalizedstring (user! language, "name")

转载请注明原文地址:https://www.9cbs.com/read-67513.html

New Post(0)