OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2
Posted 威尔逊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2相关的知识,希望对你有一定的参考价值。
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 [email protected] 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=‘‘‘[email protected]+‘‘‘‘) ;update a set a.regionGroupCH=b.regioncodeCN from kraft_sync_Store a left join KRAFT_REGIONCODES b on a.regionGroup=b.regioncodeEN where [email protected] exec sp_dropserver ‘sso‘, ‘droplogins‘ GO
以上是关于OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2的主要内容,如果未能解决你的问题,请参考以下文章
SQL - OPENDATASOURCE - 名称中带有连字符的 Excel 工作表
解决SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource&
解决SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource