Invalid ObjectName xxx.dbo.xxx, but it is there

c# dbcontext entity-framework entity-framework-6 savechanges

Question

I do not understand, why the following Code does not work:

        //Database connection
        using (var db = new KassenautomatEntities())
        {
            //Create Model
            var quittung = new WAWI_Quittungen
            {
                QuittungText = "WebInterface",
                QuittungBetrag = amount,
                QuittungDatum = DateTime.Now,
                KartenIDKassierer = 0,
                KartenIDKunde = userInfo.CardId,
                Zahlungsart = 4,
                ClientNr = WebInterfaceInfo.ClientId,
                LastPrintDate = null,
                PrintedCount = 0,
                StornoQuittungID = null,
                Status = 0
            };

            //Save Model
            db.WAWI_Quittungen.Add(quittung);
            db.SaveChanges(); //<----- Crash

I get this error:

Invalid Objectname 'KasseJournal.dbo.WAWI_Quittungen'

enter image description here

General every table works for me. This is the only one, which does not.

WAWI_Quittungen has a Primary Key with autoincrement called QuittungID, which I have not defined here, but I don't think, that is the problem.

I also deleted the table from the diagramm and added it from the database.

Something point of interest:

  • In SQL Studio it is named [Kassenautomat].[dbo].[WAWI_Quittungen] instead of KasseJournal.dbo.WAWI_Quittungen.
  • If I read from this table via entity framework, I have no problem.
  • I have done a Text Search in the entire Solution for KasseJournal but zero results.

Of course I have googled a lot. I have not one of this problems:

  • Database Trigger
  • Wrong Database connected
  • Pluralize New Object set to false

What I am missing?


Connectionstring:

 <add name="KassenautomatEntities" connectionString="metadata=res://*/Models.Database.KassenautomatModel.csdl|res://*/Models.Database.KassenautomatModel.ssdl|res://*/Models.Database.KassenautomatModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Kassenautomat;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Working Generated SQL:

SELECT 
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT 
        COUNT(1) AS [A1]
        FROM [dbo].[WAWI_Quittungen] AS [Extent1]
        WHERE [Extent1].[KartenIDKunde] = @p__linq__0
    )  AS [GroupBy1]

Not working SQL:

INSERT [dbo].[WAWI_Quittungen]([QuittungText], [QuittungBetrag], [...])
VALUES (@0, @1, @2, @3, @4, @5, @6, NULL, @7, NULL, @8)
SELECT [QuittungID]
FROM [dbo].[WAWI_Quittungen]
WHERE @@ROWCOUNT > 0 AND [QuittungID] = scope_identity()

Stacktrace:

[SqlException (0x80131904): Ungültiger Objektname 'KasseJournal.dbo.WAWI_Quittungen'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1787814
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341674
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1693
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
   System.Data.SqlClient.SqlDataReader.get_MetaData() +90
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +377
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +137
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c) +9
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +72
   System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +402
   System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +166
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) +234
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +159

[UpdateException: Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.]
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +334
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +9
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +132
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +105
   System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +11
   System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +157
   System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +21
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +162
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +221
   System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +6
   System.Data.Entity.Internal.InternalContext.SaveChanges() +113

[DbUpdateException: Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.]
   System.Data.Entity.Internal.InternalContext.SaveChanges() +196
   System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +26
   System.Data.Entity.DbContext.SaveChanges() +20
   WebInterface.Controllers.RechargeCardController.HandleSuccessPayment(Decimal amount, UserInfo userInfo) in d:\Daten\Dev\Conwell\WebInterface\Controllers\RechargeCardController.cs:336
   WebInterface.Controllers.RechargeCardController.PaymentExecute(PaymentInitViewModel model) in d:\Daten\Dev\Conwell\WebInterface\Controllers\RechargeCardController.cs:222
   lambda_method(Closure , ControllerBase , Object[] ) +180
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +434
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +60
   System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +36
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +73
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651796
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
1
1
8/20/2015 6:41:04 PM

Accepted Answer

Okay I figured it out. I give you wrong Information, sorry about that.

It was a Trigger.

I was looking into Database Triggers instead of Table Triggers. I did not know that MsSQL has a Trigger Definition for every single Table. In MySQL it is one big Trigger Table.

So I removed the Trigger and everything works fine.

1
8/21/2015 7:23:57 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow