简体   繁体   English

MVC 4-字符串或二进制数据将被截断

[英]MVC 4 - String or binary data would be truncated

When I run my code locally everything is fine, but the same code running externally I am getting a strange issue, instead of displaying a string ID on screen I am getting a message String or binary data would be truncated. 当我在本地运行代码时,一切都很好,但是在外部运行相同的代码,我遇到了一个奇怪的问题,而不是在屏幕上显示字符串ID,而是收到消息: String or binary data would be truncated.

Below is a sample of the error: 下面是错误的示例:

http://www.mydomain.com/String or binary data would be truncated.~38249/

Functions.cs Functions.cs

public string EmailBodyPaymentLink(string sysId, bool forDisplay)
{
    var sb = new StringBuilder();
    sb.Append("<p><a href='" + "http://www.mydomain.com/pID~aID/'>PAY NOW</a></p>");
    sb.Append("<p>If the link above is not clickable, please copy the following into the Address Bar of your chosen Internet Browser:</p>");
    sb.Append("<p>http://www.mydomain.com/pID~aID/</p>");
}

HomeController.cs HomeController.cs

var sbSql = new StringBuilder();
sbSql.Append("INSERT INTO [dbo].[Transactions] ");
sbSql.Append("([aID], [emailDate], [Amount], [dDate], [status], [systemID], [userID], [emailFrom]) ");
sbSql.Append("OUTPUT Inserted.[pID] ");
sbSql.Append("VALUES (");
sbSql.Append("'" + aId + "', '" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "', " + amount + ", '" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "', 'Email Sent', '" + sysId + "', '" + userDetails[1] + "', '" + emailFrom + "' ");
sbSql.Append(")");

string pId = _cf.RunSql(sbSql.ToString());

string strEmailBody = TempData["EmailHeader"].ToString().Replace("<span id='lblValue'></span>", amount) + "<p>" + emailBody + "</p>" + TempData["EmailFooter"].ToString().Replace("pID", pId).Replace("aID", aId);

This is bizarre, works locally with no issues whatsoever and I've published to our internal server via Visual Studio 2010 using FileSystem. 这很奇怪,在本地没有任何问题,我已经使用文件系统通过Visual Studio 2010发布到我们的内部服务器。

Any help would be much appreciated :-) 任何帮助将非常感激 :-)

I think the bottom line of the problem is the actual data which is passed in. My guess is one of your fields is bigger than your destination columns. 我认为问题的底线是传递的实际数据。我的猜测是您的字段之一大于目标列。

Check using SQL Profiler 使用SQL事件探查器进行检查

Check your columns in [dbo].[Transactions] Table and they may have a length which is less than the length of the data you are sending. [dbo].[Transactions]表中检查您的列,它们的长度可能小于您要发送的数据的长度。

Thanks ! 谢谢 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM