Click here to Skip to main content
15,891,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys!

I get a strange Exception that I could not handle.

Following:

I build an application which gets files from a MySQL-Database and write it to the project-folder.
I wirst wrote an Win7 Version which uses the Entity Framework 6 and was compiled by Visual Studio 2012.
Visual Studio 2012 does not support WinXP Applications, so I had to rebuild my application with the Entity Framework 5 and compiled it using Visual Studio 2010.

The Code of my application is exactly the same in both Versions.

I try to write files which are stored in a mysql-database to the local project-folder using this piece of code:

C#
//get the idProject for the Projectname & Projectversion
var idProject = (from x in ebi.project
                 where x.Projectname.Equals(project_name) && x.Projectversion.Equals(project_version)
select x.idProject);


foreach (var id in idProject)
{
//get all files that belong to the idProject & the codec
var file =(from x in ebi.documents
where x.idProject.Equals(id) && x.Folder.Equals("Codec")
select x);

foreach (var itm in file)
{
try
{
//Get and write all documents. 
System.IO.File.WriteAllBytes(foldername + itm.Document_Name, itm.File.ToArray());

}
catch (InvalidOperationException IOE)
{
// Show an error message.
MessageBox.Show("Cannot Create the Connection!\r\n" +
IOE.Message);
// Exit the event handler.
return;
..................
..................
}


It works on Win7 and Entity Framework 6 but not on the WinXP Version with Entity Framework 5.
The Exception is called: EntityCommandExcecutionException and caused by the line:

C#
//get all files that belong to the idProject & the codec
                      var file =(from x in ebi.documents
where x.idProject.Equals(id) && x.Folder.Equals("Codec")
                                 select x);



I don´t know how to handle that. Please help!

regards

Adam
Posted
Comments
Yasser Moradi DNP 25-Feb-14 5:44am    
Can you run your app which is using ef 5 on your windows 7 correctly without any exception?

I think that your windows has not any problem.

Are you trying to connect to the same database instance in both (ef5 & ef6) applications?
Member 8857897 25-Feb-14 5:48am    
No I cannot run the winxp(EF 5) version on Win7. --> Same error. I do hundreds of linq-to-entity queries on my application and all is working fine! If I put the files from the database manually into the projectfolder then the application runs without any problems!

The inner Exception says: "complus exception code -532462766" ??? I have read somewhere on the net that this query is not supported by the Entity Framework. How could that be? This is a simple query. I have queries on my application that are 100 times more complex and they work. The Mapping between the database table "documents" and the EF Model object "documents" is in both version exactly the same. File:longblob(database) <--> File:Binary(Model)

1 solution

Hi! I found the solution after I got the correct inner Exception: "There is already an open DataReader associated with this Connection which must be closed first"

I had to add .toList() after each query. --> This forces entityframework to load the list into memory, and so after one query the datareader is closed. Then the next query is performed.

Correct Code:


C#
//get the idProject for the Projectname & Projectversion
var idProject = (from x in ebi.project
                 where x.Projectname.Equals(project_name) && x.Projectversion.Equals(project_version)
select x.idProject).ToList();


foreach (var id in idProject)
{
//get all files that belong to the idProject & the codec
var file =(from x in ebi.documents
where x.idProject.Equals(id) && x.Folder.Equals("Codec")
select x).ToList();
...............
;
 
Share this answer
 
Comments
Dave Kreskowiak 25-Feb-14 7:36am    
Yeah, it help s greatly to have all of the exception messages, not the exception names.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900