简体   繁体   中英

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.

Below is a sample of the error:

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

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

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.

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

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.

Thanks !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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