.NET / Entity Framework - System.Data.UpdateException not precise enough? - c#

i got thrown into a small .NET migration project that is using the Entity Framework and MS SQL Server 2005. when persisting data that is not working with db schema (e.g. a string is too long), I am getting an exception System.Data.UpdateException that says "String or binary data would be truncated". But there is no information to which field it relates. does someone has a clue how to get this?
thx
here the stacktrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at HAM.Inventory.Data.Repository.DocumentRepository.Save(Document document) in D:\ludewigg\Documents\Projects\HAM\src\VBS-HAM-Inventory\Main\HAM.Inventory.Data\Repository\DocumentRepository.cs:line 177
at HAM.Inventory.Business.Managers.DocumentManager.Save(Document document) in D:\ludewigg\Documents\Projects\HAM\src\VBS-HAM-Inventory\Main\HAM.Inventory.Business\Managers\DocumentManager.cs:line 75
at HAM.Inventory.MigrationClient.Common.Migration.SaveItem(ItemBase item) in D:\ludewigg\Documents\Projects\HAM\src\VBS-HAM-Inventory\Main\HAM.Inventory.MigrationClient\Common\Migration.cs:line 143
at HAM.Inventory.MigrationClient.Common.Migration.SaveAndClearItems(List`1 items) in D:\ludewigg\Documents\Projects\HAM\src\VBS-HAM-Inventory\Main\HAM.Inventory.MigrationClient\Common\Migration.cs:line 76
and the inner exception:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

Look at the StateEntries property. It should have all the failing objects.

Related

Azure SQL Database - Transient Fault Handling doesn't work

I tried to use SQL Azure Transient fault handling, but it doesn't seem to work. My Web Service still throws a transient error. Here is my code:
public int ExecuteSqlCmd(string sql, object[] parameters)
{
return (new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(10, TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5))).ExecuteAction<int>(() =>
{
return this.Database.ExecuteSqlCommand(sql, sqlParams);
});
}
Every now and then, it still throws this error:
System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. ---> System.Data.SqlClient.SqlException: Transaction (Process ID 84) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreCommandInternal(String commandText, Object[] parameters)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass174_0.<ExecuteStoreCommand>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
--- End of inner exception stack trace ---
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
...
...
...
Any idea why? I have spent days trying to figure out the solution to this problem.
Thanks

How to gen a sequential unique number by difference app type

I've built a MVC web application and need to generate a unique sequential serial number by application type and year when users submit a form.
The serial number will be stored in the database table MyAppCodeSEQ and the column "AppCode" is a PK of MyAppCodeSEQ.
This is my code below:
public MyAppCodeSEQ GenNewAppCode(string appType)
{
MyAppCodeSEQ model = null;
try
{
var today = DateTime.Now;
int maxSeq = _db.MyAppCodeSEQ.Where(x => x.AppType == appType && x.Year == today.Year).Select(x => x.SEQ).DefaultIfEmpty(0).Max();
maxSeq = maxSeq + 1;
var appCode = "XX" + appType + today.Year % 1000 + string.Format("{0:000000}", maxSeq);
model = new MyAppCodeSEQ()
{
AppCode = appCode,
AppType = appType,
Year = today.Year,
SEQ = maxSeq,
};
_db.MyAppCodeSEQ.Add(model);
_db.SaveChanges();
}
catch(Exception e)
{
Thread.Sleep(100);
GenNewAppCode(appType);
}
return model;
}
The function will be recall while a duplicated key is inserted. however, the below error was occurred again and again.
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details.
---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_AppCodeSEQ'.
Cannot insert duplicate key in object 'dbo.MyAppCodeSEQ'. The duplicate key value is (XXYY18002193).
The statement has been terminated.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
System.Data.SqlClient.SqlDataReader.get_MetaData()
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption)
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
System.Data.Entity.Internal.InternalContext.SaveChanges()
Is there any better solution to generate a serial number?
a) NEVER have a primary key that is editable, let the database generate the primary key
b) The fields you are talking about is a "candidate" key and the purpose is usually for "sorting" into a default sequence or for guaranteeing uniqueness
c) A sequential key is pretty much a meaningless piece of data
That said, here's one possibility:
Alter your class (MyAppCodeSEQ) to include an Added field as DateTime. Unique Index on AppCode, AppType, Year to prevent duplicates. Index on AppCode, AppType, Year, Added to preserve sequence.

Incorrect syntax near 'ENTUserAccount'

Incorrect syntax near 'ENTUserAccount'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'ENTUserAccount'.
Source Error:
Line 76: " WHERE " + fieldName + " = {0}" +
Line 77: " AND " + fieldNameId + " <> {1}";
Line 78: var result = db.ExecuteQuery(sql, new object[] { value, id });
Line 79: List list = result.ToList();
Line 80: return (list[0].DuplicateCount > 0);
Source File: c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffDAL\Framework\ENTUserAccountData.cs Line: 78
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'ENTUserAccount'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +1753346
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5295154
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +59
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1325
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader() +12
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +1306
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +118
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +342
System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters) +83
System.Data.Linq.DataContext.ExecuteQuery(String query, Object[] parameters) +254
V2.PaidTimeOffDAL.Framework.ENTUserAccountData.IsDuplicate(HRPaidTimeOffDataContext db, String tableName, String fieldName, String fieldNameId, String value, Int32 id) in c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffDAL\Framework\ENTUserAccountData.cs:78
V2.PaidTimeOffDAL.Framework.ENTUserAccountData.IsDuplicateWindowsAccountName(HRPaidTimeOffDataContext db, Int32 userAccountId, String windowsAccountName) in c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffDAL\Framework\ENTUserAccountData.cs:69
V2.PaidTimeOffBLL.Framework.ENTUserAccountEO.Validate(HRPaidTimeOffDataContext db, ENTValidationErrors& validationErrors) in c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffBLL\Framework\ENTUserAccountEO.cs:66
V2.PaidTimeOffBLL.Framework.ENTUserAccountEO.Save(HRPaidTimeOffDataContext db, ENTValidationErrors& validationErrors, Int32 userAccountId) in c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffBLL\Framework\ENTUserAccountEO.cs:23
V2.PaidTimeOffBLL.Framework.ENTBaseEO.Save(ENTValidationErrors& validationErrors, Int32 userAccountId) in c:\Users\ClassicSofts\Documents\Visual Studio 2012\Projects\PaidTimeOffSolution\V2.PaidTimeOffBLL\Framework\ENTBaseEO.cs:49
Administration_User.Master_SaveButton_Click(Object sender, EventArgs e) in c:\Program Files\IIS\PaidTimeOffUI1\Administration\User.aspx.cs:27
PaidTimeOffEditPage.btnSave_Click(Object sender, EventArgs e) in c:\Program Files\IIS\PaidTimeOffUI1\PaidTimeOffEditPage.master.cs:27
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553594
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Entity Framework 7 Beta5 - DbUpdateException resolution

I am having issues using the Entity Framework for simple CRUD operations. I do believe everything is configured correctly, but when I call SaveChanges after adding an entity to a DbSet, a DbUpdateException is thrown. I'm not quite sure which code to provide, so I'm going to include the exception detail and the logic involved.
Exception detail:
Microsoft.Data.Entity.Update.DbUpdateException occurred
HResult=-2146233088
Message=An error occurred while updating the entries. See the inner exception for details.
Source=EntityFramework.Relational
StackTrace:
at Microsoft.Data.Entity.Relational.Update.ReaderModificationCommandBatch.Execute(RelationalTransaction transaction, IRelationalTypeMapper typeMapper, DbContext context, ILogger logger)
at Microsoft.Data.Entity.Relational.Update.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.Data.Entity.Relational.RelationalDataStore.SaveChanges(IReadOnlyList`1 entries)
at Microsoft.Data.Entity.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at Microsoft.Data.Entity.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.Data.Entity.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.Data.Entity.DbContext.SaveChanges()
at Uniti.Data.Repository`1.Add(T entity) in D:\Alex\Projects\Uniti\src\Uniti.Data\Repository.cs:line 38
InnerException:
Class=16
ErrorCode=-2146232060
HResult=-2146232060
LineNumber=2
Message=Invalid object name 'UnitiPost'.
Number=208
Procedure=""
Server=(localdb)\MSSQLLocalDB
Source=.Net SqlClient Data Provider
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.Data.Entity.Relational.Update.ReaderModificationCommandBatch.Execute(RelationalTransaction transaction, IRelationalTypeMapper typeMapper, DbContext context, ILogger logger)
InnerException:
Repository Add method
public bool Add(T entity)
{
_context.Add(entity);
_context.Entry(entity).State = EntityState.Added;
return _context.SaveChanges() > 0;
}
Controller action to add UnitiPost
[HttpPost]
[Route("Add")]
[Authorize("Bearer")]
public async Task<IActionResult> Add([FromBody] UnitiPostAddDto postAddModel)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByIdAsync(User.GetUserId());
var post = new UnitiPost
{
Creator = user,
CreateDateTime = DateTime.UtcNow,
UpdateDateTime = DateTime.UtcNow,
Content = postAddModel.Content
};
var add = Repository.Add(post);
if (!add)
{
return Json(false);
}
return Json(true);
}
return Json(new FailureResult(null, ModelState));
}
If you need more information to solve the issue, I will be able to give you individual access to my GitHub repo, but it is a private repo, so I cannot open it to everyone.

Telerik Open Access error on string with 8000 characters

I'm trying to save 8,000 characters to a SQL Server Express database table, and this may be smaller or larger in the future, and I'm getting an exception saying that the data will be truncated.
I've already set the column to varchar(max) and don't know if there is another setting for the ORM itself.
Any help is appreciated
Update failed: Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at OpenAccessRuntime.CommandWrapper.ExecuteReader(CommandBehavior behavior)
at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.RelationalStorageManager.generateUpdates(OID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, Boolean haveNewObjects, CharBuf s, BatchControlInfo batchControl, Boolean previousInserts)
Row: GenericOID#bd4840c1 TokenRequest TokenID=ae428dc3-5815-42ac-bbd6-e4a3f8e87132
UPDATE [TokenRequest] SET [PI]=?, [ReqState]=?, [second_message_date]=?, [second_message_j_s_o_n]=?, [TI]=? WHERE [TokenID] = ? AND [ReqState] is null AND [second_message_date]=?
(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at OpenAccessRuntime.CommandWrapper.ExecuteReader(CommandBehavior behavior)
at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteReader()
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate(Nullable`1 commandTimeout)
at OpenAccessRuntime.Relational.RelationalStorageManager.generateUpdates(OID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, Boolean haveNewObjects, CharBuf s, BatchControlInfo batchControl, Boolean previousInserts)
#makerofthings7, my best guess about the re-appearance of the error after the fix is that the model and the database are not in synchronous.
It seems that you have modified the table in the storage model in Visual Designer and in order to complete the fix, I would suggest to you to run the Update Database From Model wizard and to transfer the change in the database.
I hope this helps.

Categories