This is a migrated thread and some comments may be shown as answers.

Telerik.OpenAccess.RT.sql.SQLException: Invalid object name

3 Answers 410 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marty Casey
Top achievements
Rank 1
Marty Casey asked on 22 Nov 2009, 10:45 PM

I have been having issues with this error for a while so I decided to start from a blank solution. I created a project for persistent class using NorthWind, I create a web Service project and did the GetCustomers thing. I created a web app with a RADGrid. This worked. Off to a good start.

Let’s move on to using my own db. Created another persistent class Project that accesses my db make all changes needs and lo and behold I get the invalid object name error. After spending most of the day dinking around with this I renamed one table in the db and created another persistent class project to access the newly renamed table (always using reverse mapping) and this time it worked. What is going on I think to myself.

I spend more time and create more and more persistent class projects on different dbs some work most don’t. Very frustrating!!

Eventually I make a copy of the entire db that I was able to get the one table to work with and rename all the tables to see if that will help... nope same error, including now fo rthe table that did work. I decided to try this. Using the new database which is a backup/restore of the one persistent class example I do have working. I create another persistent class with just the one working table in it. Make all needed changes and nope invalid object name error again. Telerik name had been used in vain many times at this point.

Lets do a diff on the class that works vs the one that doesn’t.

Results of file dff's:

Class.cs is that same except for namespace,
Class.Telerik.OpenAcess.cs same except for namespace
ReverseMapping.cs – same except for the names of other tables in db since I renamed them all.
ObjectScopeProvider.cs – same
App.config same except for namespace.

At this point I can swap the classes in and out of the webService and web app and replicate the issue at will. These are the steps I do to replicate the error: lets us assume Class1 works and Class2 gives us the Invalid Object Name error.

Web Service project

1.    Remove Class1 reference

2.    Add Class2 reference

3.    Update config references

4.    Change the using statement to class2

5.    Rebuild

Web App project

1.    Remove Class1 reference

2.    Add Class2 reference

3.    Update config references

4.    Browse default.aspx get error

Repeat steps to change back to Class 1 and browse default.aspx. No error and RadGrid is populated

At this point Telerik owes me some time and to say I did due diligence on this would be an understatement, Also I have read all I could find in the forums including this one http://www.telerik.com/community/forums/orm/general-discussions/always-getting-error-executing-query-telerik-openaccess-rt-sql-sqlexception.aspx

I am not buying into the config error and it would not explain how I was able to rename the table and then have the issue go away when I first started.  As a last resort I did change the connection string in the Class2 to the db in the working Class1 and received the same error. Table name and columns and data for that table are all the same.

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 23 Nov 2009, 02:01 PM
Hi Marty Casey,

If you have defined a connection string in both your web config.file and your app.config file and they have the same id then the one from the web.config file will be used ( this is the case with your web service and your DasClass class library). However if the IDs differ, the one from the web.config file is ignored and the one from the app.config file is respected. This is the reason for which your project worked with the Hosts class library and failed with the DasClass one. What you will need to do if you would like to leave your connection string in the web.config file would be to change its ID to an unique one. This should solve your problem.

All the best,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ben Bolton
Top achievements
Rank 1
answered on 24 Nov 2009, 07:02 PM
Is there anything that can be done about the error message in this case.

Invalid object name is very vague.  In this particular instance the web.config file is pointing to the wrong database.  I wouldn't expect the ORM injected code to know that, but I would expect it knows if the table that is used to retrieve the Host object doesn't exist in the database.   Invalid object name doesn't lead the tester to any understanding of why there is a problem.

1) is there a way to get this information (a test to confirm the database is "up to date" for all the persistable objects?)
2) could the error message be enhanced to indicate "the data table XXX doesn't exist in the YYY database" pointing out the real underlying problem?
0
PetarP
Telerik team
answered on 27 Nov 2009, 02:31 PM
Hi Ben Bolton,

1. You want to be able to check if the database is up to date during runtime or during design time? If you want this during runtime, you can just prepare a DDL script which will update the database. To generate a script and execute it you can use the methods of a ISchemaHandler instance. Such instance could be created by calling the ObjectScopeProvider.Database().GetSchemaHandler() method. If the script is null, the database is up to date.
During design time you can use the merge option of the Reverse mapping wizard to do the check.

2. Thank you for the suggestion, we will consider changing the message to a more meaningful one.

All the best,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Marty Casey
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Ben Bolton
Top achievements
Rank 1
Share this question
or