Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
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:
JavaScript
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
Posted

1 solution

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
C#
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?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900