分享
 
 
 

SQL Server 2000 Reporting Services: 怎样根据用户的语言偏好显示本地化的信息

王朝mssql·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Microsoft的Reporting Servcies发布以来,由于其简单易用,功能强大,越来越多的用户选择它来做为报表解决方案。在当今国际化的大趋势下,很多用户在使用Reporting Servcies的时候会遇到一个难题,那就是怎样根据用户的语言偏好显示本地化的信息,比如为中国的用户显示中文的报表标题,为美国的用户显示英文的报表标题;还有如为不同国家的用户显示不同的货币符号等。本文提供了解决这个问题的两个方法.

方法1:

Let’s suppose you want to display column names for different users (for example,

for Chinese users, display “姓名”; for other users, display “Name”,), you may use

expressions to do so as follows:

=IIF( User!Language = "zh-CN","姓名","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 “zh-CN”.

For more information regarding User!Language, please refer to MSDN.

方法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 then call this assembly in your report. The detailed steps are:

1. 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'姓名')

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 destStr from

localizationTbl where language = '" + language + "' and sourceStr = '" + sourceStr

+ "'";

cmd.CommandType = CommandType.Text;

cmd.Connection = conn;

conn.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):

<CodeGroup class="UnionCodeGroup"

version="1"

PermissionSetName="FullTrust"

Name="localized_string"

Description="">

<IMembershipCondition class="UrlMembershipCondition"

version="1"

Url="file://c:/Program Files/Microsoft SQL

Server/MSSQL/Reporting Services/ReportServer/bin/getLocalString.dll"/>

</CodeGroup>

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 References dialog box.

6. Then you may use expression in the Report to call the static method defined in the assembly as follows:

=getLocalString.Class1.GetLocalizedString( User!Language ,"Name")

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有