如何插入包含希伯来语文本的 html 文件并使用 filestream 选项在 sql server 2008 中读回它?
我是 sql server 2008 中 filestream 选项的新手, 但我已经了解如何打开此选项以及如何创建一个允许您保存文件的表。 假设我的表包含: id、name、filecontent
我尝试将一个 html 文件(其中包含希伯来语字符/文本)插入到该表中。 我正在使用 Visual Studio 2008 在 asp.net (c#) 中编写。
但是当我尝试读回内容时,希伯来语字符变成了“?”。
我采取的行动是:
1.我像这样读取文件:
// open the stream reader
System.IO.StreamReader aFile = new StreamReader(FileName, System.Text.UTF8Encoding.UTF8);
// reads the file to the end
stream = aFile.ReadToEnd();
// closes the file
aFile.Close();
返回流; // 返回流
我将“流”作为二进制数据插入到文件内容列。
我尝试对此列进行“选择”,数据确实返回(在我将其转换回字符串之后),但希伯来语字符变成了“?”
我该如何解决这个问题? 我应该注意什么?
谢谢, 加迪姆
i am new to the filestream option in sql server 2008,
but i have already understand how to open this option and how to create a table that allow you to save files.
let say my table contains:
id,name, filecontent
i tried to insert an html file (that has hebrew chars/text in it) to this table.
i'm writing in asp.net (c#), using visual studio 2008.
but when i tried to read back the content , hebrew char becomes '?'.
the actions i took were:
1. i read the file like this:
// open the stream reader
System.IO.StreamReader aFile = new StreamReader(FileName, System.Text.UTF8Encoding.UTF8);
// reads the file to the end
stream = aFile.ReadToEnd();
// closes the file
aFile.Close();
return stream; // returns the stream
i inserted the 'stream' to the filecontent column as binary data.
i tried to do a 'select' to this column and the data did return (after i coverted it back to string) but hebrew chars become '?'
how do i solve this problem ?
what I should pay attention to ?
thanks,
gadym
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我成功解决了这个问题。
我错了,问题不在 sql server 中,而是在我的代码中,当我将其从二进制传输到字符串时,反之亦然。
当您需要将字符串(具有希伯来字符)转换为二进制时,您可以编写以下行:
反之亦然:
出于某种原因,我使用 System.Text.ASCIIEncoding 而不是 System.Text.UTF8Encoding。
谢谢梅夫!
I succeeded to solve this problem.
I was wrong , the problem wasnt in the sql server , but in my code, when i transfer it from binary to string and vice versa.
when you need to convert string (that have hebrew chars) to binary you can write the following lines:
and vice versa :
i used for some reason System.Text.ASCIIEncoding instead of System.Text.UTF8Encoding.
thank you Meff !
看起来 UTF8 编码可能不适用于希伯来语?
请参阅此处查看较早的讨论:http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/73c81574-b434-461f-b766-fb9d0e4353c7
或者,您确定该文件是用 UTF8 编码的吗?
另外,如果 BLOB 小于 1MB,并且我希望 HTML 文件符合该描述,则 FILESTREAM 实际上可能表现更差。您是否考虑过 NVARCHAR(MAX)?
http:// blogs.msdn.com/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx
Looks like the UTF8 encoding may not work with the Hebrew?
See here for an older discussion: http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/73c81574-b434-461f-b766-fb9d0e4353c7
Alternatively, are you sure the file is encoded in UTF8?
Also, FILESTREAM may actually perform worse if the BLOB is under 1MB, and HTML files I would expect to fit that description. Have you considered NVARCHAR(MAX) instead.
http://blogs.msdn.com/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx