Linq Calls Fail Silently When Table or SProc Not Found
- I just ran into something really weird involving Linq to SQL. I have some code in an ASP.NET code-behind file which queries against some tables:
var temp = (from mi in myDataContext.memberInfo
where mi.Id == 10
select mi).SingleOrDefault();
This worked fine on my development server, but failed when I moved it to a hosted production environment.
The reason was because the db schema/owner of the table had changed from "dbo" in the development database to "myRemoteUser" in the production database.
But here's the really upsetting thing: it didn't fail with an exception or an error. It just failed silently, with no message or warning.
I don't think that should happen. If Linq can't find an object in the database it ought to throw an exception.
- Mark
p.s. It occurs to me as I write this that maybe the SingleOrDefault() operator was hiding the failure. But, if so, I don't think it should do that when the database object that Linq is expecting to find can't be found.
Answers
Hi Mark,
Welcome to LINQ Project General forum!
Have you installed the latest service pack (SP1) of Visual Studio 2008? If not, you can download and install it from this link, http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&displaylang=en.
I tried to reproduce this problem at my Visual Studio 2008 SP1 machine but the similar query raised an SqlException saying “Invalid object name ‘dbo.TABLENAME’”, if I have no such table in the database. The SingleOrDefault() will return the only element of a sequence or a default value if the sequence is empty. It also will throws an exception if there is more than one element in the sequence.
Besides, you have mentioned that the application is failed silently. Could you please tell me what the temp variable is after the query is executed? Does the database still contain the original tables under schema dbo?
Important to mention, if the only the schema name of the table is modified and the table structure is kept, we can directly modified the .dbml file.
1. In .dbml O/R designer, select the Table entity.
2. In the table’s properties window, set the schema information in property Source.
Have a nice weekend!
Best Regards,
Lingzhi SunP.S. For LINQ to SQL problems, I recommend you post at LINQ to SQL MSDN Forum here for better support, http://social.msdn.microsoft.com/Forums/en-US/linqtosql/threads. LINQ Project General forum is archived forum for old LINQ version and beta versions.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Proposed As Answer byLingzhi SunMSFT, ModeratorWednesday, November 04, 2009 1:04 AM
- Marked As Answer byLingzhi SunMSFT, ModeratorWednesday, November 11, 2009 10:09 AM
All Replies
Hi Mark,
Welcome to LINQ Project General forum!
Have you installed the latest service pack (SP1) of Visual Studio 2008? If not, you can download and install it from this link, http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&displaylang=en.
I tried to reproduce this problem at my Visual Studio 2008 SP1 machine but the similar query raised an SqlException saying “Invalid object name ‘dbo.TABLENAME’”, if I have no such table in the database. The SingleOrDefault() will return the only element of a sequence or a default value if the sequence is empty. It also will throws an exception if there is more than one element in the sequence.
Besides, you have mentioned that the application is failed silently. Could you please tell me what the temp variable is after the query is executed? Does the database still contain the original tables under schema dbo?
Important to mention, if the only the schema name of the table is modified and the table structure is kept, we can directly modified the .dbml file.
1. In .dbml O/R designer, select the Table entity.
2. In the table’s properties window, set the schema information in property Source.
Have a nice weekend!
Best Regards,
Lingzhi SunP.S. For LINQ to SQL problems, I recommend you post at LINQ to SQL MSDN Forum here for better support, http://social.msdn.microsoft.com/Forums/en-US/linqtosql/threads. LINQ Project General forum is archived forum for old LINQ version and beta versions.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Proposed As Answer byLingzhi SunMSFT, ModeratorWednesday, November 04, 2009 1:04 AM
- Marked As Answer byLingzhi SunMSFT, ModeratorWednesday, November 11, 2009 10:09 AM
Hi Mark,
Do you need any further assistance? If so, please feel free to let me know.
Have a nice day!Best Regards,
Lingzhi Sun
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Sorry, I wasn't getting email notification that you'd replied, and I didn't stop back to check.
I will do some more research based on your first response and get back to you.
- Mark Hi Mark,
How's the problem? If you have any questions, please be free to let me know.
Have a nice day!Best Regards,
Lingzhi Sun
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

