Very strange SqlClient error in page code?

A

Andy B.

I am using entity framework to create database data access code. For some
wierd reason, I keep getting the following error but I don't even have an
object in the database with the name the error claims is invalid. I used to
have a database table with that name but since deleted it ages ago. Any way
to fix the problem? I even went so far as to create a brand new web project
and hand ported code over but the error keeps coming up. I can create and
add new objects and delete objects but for some reason I can't update
objects. Here is the error:


Server Error in '/' Application.
--------------------------------------------------------------------------------

Invalid object name 'News.News'.
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: Invalid object name
'News.News'.

Source Error:

Line 55:
Line 56:
Line 57: Return DBContext.SaveChanges()
Line 58: End Function
Line 59:

Source File: C:\Documents and Settings\Andy B\My Documents\Visual Studio
2008\Projects\Eternity Records\Website\Modules\News.vb Line: 57

Stack Trace:

[SqlException (0x80131904): Invalid object name 'News.News'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) +1950890
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +4846875
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) +204
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
+954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +175
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator
translator, EntityConnection connection, Dictionary`2 identifierValues,
List`1 generatedValues) +554
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager
stateManager, IEntityAdapter adapter) +281

[UpdateException: An error occurred while updating the entries. See the
InnerException for details.]
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager
stateManager, IEntityAdapter adapter) +491
System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager
entityCache) +117
System.Data.Objects.ObjectContext.SaveChanges(Boolean
acceptChangesDuringSave) +453
System.Data.Objects.ObjectContext.SaveChanges() +9
Website.News.News.UpdateNews(Guid NewsID, String Title, String
Description, String Body) in C:\Documents and Settings\Andy B\My
Documents\Visual Studio 2008\Projects\Eternity
Records\Website\Modules\News.vb:57
Website.News.UI.Edit.EditNewsWizard_NextButtonClick(Object sender,
WizardNavigationEventArgs e) in C:\Documents and Settings\Andy B\My
Documents\Visual Studio 2008\Projects\Eternity
Records\Website\Controls\News\Edit.ascx.vb:33
System.Web.UI.WebControls.Wizard.OnNextButtonClick(WizardNavigationEventArgs
e) +108
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs
e) +418
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source,
EventArgs args) +19
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+166
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) +36
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
 
G

Göran Andersson

Andy said:
I am using entity framework to create database data access code. For some
wierd reason, I keep getting the following error but I don't even have an
object in the database with the name the error claims is invalid. I used to
have a database table with that name but since deleted it ages ago. Any way
to fix the problem? I even went so far as to create a brand new web project
and hand ported code over but the error keeps coming up. I can create and
add new objects and delete objects but for some reason I can't update
objects. Here is the error:

Well, there is something left in your code that uses the table. If you
look in the call stack, the error occurs in this method:

Website.News.News.UpdateNews

It seems logical that a method named that way would try update the News
table.
 
A

Andy B.

I know. The problem is that i rewrote the code for that method 20 times
today and there was no reference to an object called News.News anywhere in
the 20 rewrites. I have no idea why ObjectContext.SaveChanges is
complaining. Here is the code for the entire thing.

'*** Update a news article.

'*** Returns the total number of updated news articles.

'*** 0 = Nothing was changed/updated.

'*** Anything over 0 = Total number of updated/changed news articles.

Public Function UpdateNews(ByVal NewsID As Guid, ByVal Title As String,
ByVal Description As String, ByVal Body As String) As Integer

Dim NewsArticle As NewsArticles = _

DBContext.NewsArticles.Where("it.ID = @NewsID", New
ObjectParameter("NewsID", NewsID)).First()

NewsArticle.Body = Body

NewsArticle.Description = Description

NewsArticle.LastModified = Date.Now

NewsArticle.Title = Title

Return DBContext.SaveChanges()

End Function
 
A

Andy B.

I found the problem. I had to track the problem all the way back to a
trigger in the database that had a wrong table name in it. Everything works
fine now.


Andy B. said:
I know. The problem is that i rewrote the code for that method 20 times
today and there was no reference to an object called News.News anywhere in
the 20 rewrites. I have no idea why ObjectContext.SaveChanges is
complaining. Here is the code for the entire thing.

'*** Update a news article.

'*** Returns the total number of updated news articles.

'*** 0 = Nothing was changed/updated.

'*** Anything over 0 = Total number of updated/changed news articles.

Public Function UpdateNews(ByVal NewsID As Guid, ByVal Title As String,
ByVal Description As String, ByVal Body As String) As Integer

Dim NewsArticle As NewsArticles = _

DBContext.NewsArticles.Where("it.ID = @NewsID", New
ObjectParameter("NewsID", NewsID)).First()

NewsArticle.Body = Body

NewsArticle.Description = Description

NewsArticle.LastModified = Date.Now

NewsArticle.Title = Title

Return DBContext.SaveChanges()

End Function
 
J

James Campbell

Trigger on the table was causing the problem. I renamed the table but not the trigger. You saved me alot of time trying to hunt this down.



Andy B. wrote:

[solved] Very strange SqlClient error in page code?
10-Feb-09

I found the problem. I had to track the problem all the way back to
trigger in the database that had a wrong table name in it. Everything work
fine now.

Previous Posts In This Thread:

Very strange SqlClient error in page code?
I am using entity framework to create database data access code. For some
wierd reason, I keep getting the following error but I don't even have an
object in the database with the name the error claims is invalid. I used to
have a database table with that name but since deleted it ages ago. Any way
to fix the problem? I even went so far as to create a brand new web project
and hand ported code over but the error keeps coming up. I can create and
add new objects and delete objects but for some reason I can't update
objects. Here is the error

Server Error in '/' Application
-------------------------------------------------------------------------------

Invalid object name 'News.News'
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: Invalid object name
'News.News'

Source Error

Line 55
Line 56
Line 57: Return DBContext.SaveChanges(
Line 58: End Functio
Line 59

Source File: C:\Documents and Settings\Andy B\My Documents\Visual Studio
2008\Projects\Eternity Records\Website\Modules\News.vb Line: 5

Stack Trace

[SqlException (0x80131904): Invalid object name 'News.News'.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) +195089
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +484687
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +19
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj) +239
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) +20
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
+95
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) +16
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +17
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +13
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator
translator, EntityConnection connection, Dictionary`2 identifierValues,
List`1 generatedValues) +55
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager
stateManager, IEntityAdapter adapter) +28

[UpdateException: An error occurred while updating the entries. See the
InnerException for details.
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager
stateManager, IEntityAdapter adapter) +49
System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager
entityCache) +11
System.Data.Objects.ObjectContext.SaveChanges(Boolean
acceptChangesDuringSave) +45
System.Data.Objects.ObjectContext.SaveChanges() +
Website.News.News.UpdateNews(Guid NewsID, String Title, String
Description, String Body) in C:\Documents and Settings\Andy B\My
Documents\Visual Studio 2008\Projects\Eternity
Records\Website\Modules\News.vb:5
Website.News.UI.Edit.EditNewsWizard_NextButtonClick(Object sender,
WizardNavigationEventArgs e) in C:\Documents and Settings\Andy B\My
Documents\Visual Studio 2008\Projects\Eternity
Records\Website\Controls\News\Edit.ascx.vb:33
System.Web.UI.WebControls.Wizard.OnNextButtonClick(WizardNavigationEventArgs
e) +108
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs
e) +418
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source,
EventArgs args) +19
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+166
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) +36
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082;
ASP.NET Version:2.0.50727.3082

Re: Very strange SqlClient error in page code?
Andy B. wrote:

Well, there is something left in your code that uses the table. If you
look in the call stack, the error occurs in this method:

Website.News.News.UpdateNews

It seems logical that a method named that way would try update the News
table.


--
G?ran Andersson
_____
http://www.guffa.com

I know.
I know. The problem is that i rewrote the code for that method 20 times
today and there was no reference to an object called News.News anywhere in
the 20 rewrites. I have no idea why ObjectContext.SaveChanges is
complaining. Here is the code for the entire thing.

'*** Update a news article.

'*** Returns the total number of updated news articles.

'*** 0 = Nothing was changed/updated.

'*** Anything over 0 = Total number of updated/changed news articles.

Public Function UpdateNews(ByVal NewsID As Guid, ByVal Title As String,
ByVal Description As String, ByVal Body As String) As Integer

Dim NewsArticle As NewsArticles = _

DBContext.NewsArticles.Where("it.ID = @NewsID", New
ObjectParameter("NewsID", NewsID)).First()

NewsArticle.Body = Body

NewsArticle.Description = Description

NewsArticle.LastModified = Date.Now

NewsArticle.Title = Title

Return DBContext.SaveChanges()

End Function


[solved] Very strange SqlClient error in page code?
I found the problem. I had to track the problem all the way back to a
trigger in the database that had a wrong table name in it. Everything works
fine now.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Make Your Apps Talk to Each Other: Asynchronous Named Pipes Library
http://www.eggheadcafe.com/tutorial...0-5acdaeb00162/make-your-apps-talk-to-ea.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top