保存到SQL Server数据库时,Outlook邮件不正确 [英] Outlook mail is not correct when saved to SQL server database

查看:77
本文介绍了保存到SQL Server数据库时,Outlook邮件不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。由于迫在眉睫的截止日期,我有一个严重的问题需要立即解决。每当我将outlook邮件正文保存到我的sql server数据库中时,内容邮件就会以某种方式混淆。这是我的问题的一个例子:



ropbox - Outlook.jpg [ ^ ]



正如您所看到的,我需要保留原始邮件,以便正确解析它包含的邮件数据,因为它直接插入记录到我的数据库。但由于它在保存时包含错误的数据,因为数据不匹配,每次调用insert sql语句时我的应用程序都会失败。



我的代码中没有特殊的格式。它看起来像这样:





 '  x标记正在处理的当前邮件的索引号
Dim oMsg As Outlook.MailItem = msgItm.Item(x)
QRY =Insert到mytable(...,msgbody)值(...,oMsg.Body)





然后执行执行查询和没有错误。但是当我查看保存的值时,msgbody列数据已经混淆了。我真的很傻到如何正确地解决这个问题。我真的很感激任何有关如何解决这个问题的任何提示或帮助非常感谢,并期待您的即时反馈:)



我尝试过:



试图删除新的行字符但仍然没有用。尝试用下划线替换空格但得到相同的结果。:(

解决方案

认为解决方案是sim但首先是:我希望上面的示例代码只包含语法错误,因为您简化了语句?否则statemt应如下所示:

 QRY =插入mytable(...,msgbody)值(...,'& oMsg.Body& ')





第二:如果您使用的是字符串列(varchar或nvarchar),并且邮件正文包含有字符的字符SQL语言中的特殊含义在执行QRY时会导致语法错误。您必须搜索并替换或转义可能导致语法错误的所有字符或(更好)使用带有Parameter的SQLCommand类正确插入值(如果消息包含SQL语句,这也将阻止SQL注入)。 BLOCKQUOTE>

Hi. I have a grave problem that needs to be immediately resolved due to a looming deadline. Whenever I save outlook mail body into my sql server database, the contents message are somehow mixed up. Here's the an illustration of my problem:

ropbox - Outlook.jpg[^]

As you can see, I need to preserve the original message in order to properly parse the message data it contains as it directly inserts records to my database. But since it contains erroneous data when saved, my application fails everytime I invoke insert sql statement because of data mismatch.

I have done no special formatting in my code. It somehow looks like this :


'x marks the index number of the current mail item being processed
Dim oMsg As Outlook.MailItem = msgItm.Item(x) 
QRY = "Insert into mytable( ..., msgbody) values (...,oMsg.Body)



then perform executenonquery and there were no errors. But when I look up the values saved the msgbody column data is already mixedup. I'm really dumbfounded as to how to properly troubleshoot this matter. I would really appreciate any hints or help from anyone on how to solve this. Many thanks in advance and looking forward to your immediate feedbacks :)

What I have tried:

tried to remove new line characters and still it didnt work. tried replacing spaces with underscore but got the same result. :(

解决方案

Think the solution is simple but first of all: I hope the example code above contains the syntax error only because you simplified the statement? Otherwise the statemt should look like this:

QRY = "Insert into mytable( ..., msgbody) values (...,'" & oMsg.Body & "')"



Second: If you're using a string column (varchar or nvarchar) and the message body contains chars that have special meaning in SQL language this will lead into a syntax error when executing QRY. You either have to search and replace or escape all chars that may cause a syntax error or (better) use the SQLCommand class with Parameter to insert the value correctly (this will also prevent from SQL injection if message contains an SQL statement).


这篇关于保存到SQL Server数据库时,Outlook邮件不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆