码迷,mamicode.com
首页 > 数据库 > 详细

OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2

时间:2017-01-03 19:30:42      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:region   pass   lol   des   数据库数据   false   数据   server   log   

 

insert into kraft_sync_Store(StoreName,StoreCode,Province,PrefectureCity,CountyCity,Region,Area,Unit,HQKA,KAName,StoreType,IsValid,ContactPerson,MobileTelephone,Telephone,Address,Latitude,Longitude,regiongroup,sfastoremanagername)
	Select CAST(storename as nvarchar(500)),StoreCode,Province,PrefectureCity,CountyCity,Region,Area,Unit,HQKA,KAName,StoreType,IsValid,ContactPerson,MobileTelephone,Telephone,Address,Latitude,Longitude,regiongroup,sfastoremanagername From OPENDATASOURCE(
       ‘SQLOLEDB‘,‘Data Source=10.100.6.114;User ID=ISMEA;Password=IE1q2w3e4r‘
    ).WARIS.dbo.I_V_Store

 对于多语言版本数据库之间的读取,有可能出现中文乱码的可能。 所以以上代码中 OPENDATASOURCE读取远程数据库乱码的情况。 应该换成下面linkserver的方式: 


create  procedure [dbo].[sp_GetSyncStore_Insert]
@storecode nvarchar(500)
 as
if not exists(select name from sys.servers where name = ‘sso‘)
begin
 exec sp_addlinkedserver   ‘sso‘, ‘ ‘, ‘SQLOLEDB ‘, ‘10.100.6.114‘ 
 exec sp_addlinkedsrvlogin ‘sso‘, ‘false ‘,null, ‘ISMEA‘, ‘IE1q2w3e4r‘ 
end
delete kraft_sync_Store where StoreCode=@storecode
exec(‘insert into kraft_sync_Store(StoreName,StoreCode,Province,PrefectureCity,CountyCity,Region,Area,Unit,HQKA,KAName,StoreType,IsValid,ContactPerson,MobileTelephone,Telephone,Address,Latitude,Longitude,regiongroup,sfastoremanagername,storeTypeGroup,regionGroupCH,createtime)
select StoreName,StoreCode,Province,PrefectureCity,CountyCity,Region,Area,Unit,HQKA,KAName,StoreType,IsValid,ContactPerson,MobileTelephone,Telephone,Address,Latitude,Longitude,regiongroup,sfastoremanagername,storeTypeGroup,‘‘‘‘,GETDATE() createtime from sso.WARIS.dbo.I_V_Store  where storecode=‘‘‘+@storecode+‘‘‘‘)

;update a set a.regionGroupCH=b.regioncodeCN from kraft_sync_Store a
left join KRAFT_REGIONCODES b on a.regionGroup=b.regioncodeEN
where a.StoreCode=@storecode

exec sp_dropserver  ‘sso‘, ‘droplogins‘

GO

  

OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2

标签:region   pass   lol   des   数据库数据   false   数据   server   log   

原文地址:http://www.cnblogs.com/Wilson6/p/6245553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!