当前位置: 移动技术网 > IT编程>数据库>MSSQL > [转]sp_OACreate WriteLine Writing nvarchar 中文汉字 非乱码to a text file

[转]sp_OACreate WriteLine Writing nvarchar 中文汉字 非乱码to a text file

2018年06月01日  | 移动技术网IT编程  | 我要评论

我们的祖国,杜汶泽肉蒲团,利来国际返利送金

本文转自:https://stackoverflow.com/questions/48135889/writing-nvarchar-to-a-text-file

According to the Scripting.FileSystemObject documentation, the CreateTextFile method takes a Boolean value to create a Unicode file. You could change the T-SQL code to use that method instead of OpenTextFile.

EDIT:

Below is an example using OpenTextFile per Tom's comment. I change the iomode value in your original code from 1 to 8 to match the documentation and added the close and destroy in case your full code is missing those important tasks.

DECLARE @OLE INT;
DECLARE @FileId INT;
DECLARE @File VARCHAR(max) = 'c:\test.txt';
DECLARE @Text NVARCHAR(max) = N'من نمایش داده نمیشم';

EXECUTE sp_OACreate 'Scripting.FileSystemObject',@OLE OUT;
EXECUTE sp_OAMethod @OLE, 'OpenTextFile', @FileId OUT, @File,8,1,-1;
EXECUTE sp_OAMethod @FileId, 'WriteLine', Null, @Text;
EXECUTE sp_OAMethod @FileId, 'Close';
EXECUTE sp_OADestroy @FileId OUT;
EXECUTE sp_OADestroy @OLE OUT;


 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网