在JScript中使用的ADO - 通过参数化存储过程保存的数据在捷克语和法语系统上不同 [英] ADO used in JScript - Data saved through parametrized stored procedure different on czech and french system

查看:116
本文介绍了在JScript中使用的ADO - 通过参数化存储过程保存的数据在捷克语和法语系统上不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



我在工作中遇到了奇怪的问题。

当我从JScript调用存储过程时(Jscript代码)由第三方桌面应用程序编译,使用Windows脚本5.6)并通过参数提供数据,最终存储在数据库中的数据根据​​我使用的微软Windows的本地化而定(不同的是czech和fench)。



我们使用SQL server 2008 R2 express作为数据库。



这是Jscript代码:

  function  file_addBinaryData(ProductionProfileID,RowData,create,DB){
var connectionstring = Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info = False; Initial Catalog = ABN_EXTENSIONS;数据源= + DB + ;;
var sp_file_row = new ActiveXObject( ADODB.Command);
var ret;
var conn = new ActiveXObject( ADODB.connection);
conn.ConnectionString = connectionstring;
conn.Open();
sp_file_row.ActiveConnection = conn;
sp_file_row.CommandText = sp_addData_DPP;
sp_file_row.CommandType = adCmdStoredProc;

sp_file_row.Parameters.Append(sp_file_row.CreateParameter( RETURN_VALUE, adInteger,adParamReturnValue));
sp_file_row.Parameters.Append(sp_file_row.CreateParameter( @ ProductionProfileID,adInteger,adParamInput ,adDefaultSize,ProductionProfileID));
sp_file_row.Parameters.Append(sp_file_row.CreateParameter( @ Type,adInteger,adParamInput ,adDefaultSize, 1250 ));
sp_file_row.Parameters.Append(sp_file_row.CreateParameter( @ data,adBinary,adParamInput ,adMaximumSize,RowData));
sp_file_row.Parameters.Append(sp_file_row.CreateParameter( @ Create,adBoolean,adParamInput ,adDefaultSize,create));
sp_file_row.Execute();
ret = sp_file_row.Parameters( RETURN_VALUE);
sp_file_row.ActiveConnection.Close();

return ret;
}





存储过程本身只是插入表格。



数据是二进制的,由第三方软件提供给它们,它们将它们存储为varbinary,当它将它们提供给Jscript变量时,它被作为一个字符串处理,并且二进制数据的每个字节都被转换成unicode。然后,当我将它存储到数据库中时,它被存储到varbinary列中,作为二进制数据中原始字节的unicode represtentation。

但是当我在捷克语和法语系统上运行此函数时,存储在我的数据库中的二进制数据的差异看起来很奇怪,因为unicode shoudl在所有系统上都是相同的。



有没有人遇到过在不同语言系统上编码的问题解决了吗?



谢谢Michal

解决方案

最终我能够解决这个问题。



所有这些都是由ADO及其从本地系统语言代码页编码二进制数据到unicode时的行为引起的。



在这个例子中它是在法语系统上从代码页1252到unicode,在捷克语从代码页1250到unicode。



所以我需要更新我的程序才能工作二进制数据根据本地系统的不同而不同。

我是用

 CultureInfo.CurrentCulture.TextInfo.ANSICodePage; 



然后我将unicode二进制文件转换为原始二进制数据。



但是如果有人我很感兴趣知道是否有可能以某种方式将ADO转换为unicode?

Good day all,

I encountered were strange problem during my work.
When I call stored procedure from JScript (Jscript code is compiled by 3rd party desktop application that uses windows script 5.6) and give it data through parameters it ends up that data stored in database are different based on which localization of microsoft windows i use(eq. czech and fench).

We are using SQL server 2008 R2 express as database.

Here is Jscript code:

function file_addBinaryData(ProductionProfileID, RowData, create, DB) {
	var connectionstring = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ABN_EXTENSIONS;Data Source=" + DB + ";";
	var sp_file_row = new ActiveXObject("ADODB.Command");
	var ret;
	var conn = new ActiveXObject("ADODB.connection");
	conn.ConnectionString = connectionstring;
	conn.Open();
	sp_file_row.ActiveConnection = conn;
	sp_file_row.CommandText = "sp_addData_DPP";
	sp_file_row.CommandType = adCmdStoredProc;

	sp_file_row.Parameters.Append(sp_file_row.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue));
	sp_file_row.Parameters.Append(sp_file_row.CreateParameter("@ProductionProfileID", adInteger, adParamInput, adDefaultSize, ProductionProfileID));
	sp_file_row.Parameters.Append(sp_file_row.CreateParameter("@Type", adInteger, adParamInput, adDefaultSize, 1250));
	sp_file_row.Parameters.Append(sp_file_row.CreateParameter("@data", adBinary, adParamInput, adMaximumSize, RowData));
	sp_file_row.Parameters.Append(sp_file_row.CreateParameter("@Create", adBoolean, adParamInput, adDefaultSize, create));
	sp_file_row.Execute();
	ret = sp_file_row.Parameters("RETURN_VALUE");
	sp_file_row.ActiveConnection.Close();

	return ret;
}



Stored procedure itself is doing just insert into table.

Data are binary and are given to function by 3rd party software which stores them as varbinary and when It gives them to Jscript variable it''s handled as a String and every byte of binary data is converted into unicode. Then when I''m storing it into Database it''s stored into varbinary column as a unicode represtentation of original bytes from binary data.
But when I run this function on czech and french system there is difference in binary data stored in my database which seems strange as unicode shoudl be same on all systems.

Did anyone ever encountered such a problem with encoding on different language systems and solved it?

Thank you Michal

解决方案

in the end i was able to solve this problem.

All was caused by ADO and its behavior when it encoded binary data from Local system language codepage to unicode.

in this example it was on French system from codepage 1252 to unicode and on Czech from codepage 1250 to unicode.

So I needed to update my program to work with binary data differently according to local system.
I did it using

CultureInfo.CurrentCulture.TextInfo.ANSICodePage; 


and then I transoformed unicode binary to origibnal binary data.

But I''m interested if anyone knows if it''s possible to froce somehow ADO to not convert data to unicode?


这篇关于在JScript中使用的ADO - 通过参数化存储过程保存的数据在捷克语和法语系统上不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆