问题:从mysql导入到sql的汉字都是乱码或者干脆导入不成功,报”截断字符串“错误,错在mysql当时建立的都是使用的默认编码latin1;搞不明白,又不是瑞典人,你用这个干毛。导致现在遇到n多问题,但又不能让对方改动编码;
解决方案:只能从ssis入手,添加数据转换类型的脚本组件>添加输入输出列>编写代码,手动转换字符串
public class ScriptMain : UserComponent
{
public override void PreExecute()
{
base.PreExecute();
/*
Add your code here for preprocessing or remove if not needed
*/
}
public override void PostExecute()
{
base.PostExecute();
/*
Add your code here for postprocessing or remove if not needed
You can set read/write variables here, for example:
Variables.MyIntVar = 100
*/
}
public override void 输入0_ProcessInputRow(输入0Buffer Row)
{
/*
Add your code here
*/
Row.protonamegbk = Latin1ToGB2312(Row.protoname);
}
public static string Latin1ToGB2312(string srcString)
{
Encoding lat = Encoding.GetEncoding("latin1");
byte[] lbs = lat.GetBytes(srcString);
return Encoding.GetEncoding("gbk").GetString(lbs);
}
}