An Access database is used in a project.
There is no exception in the local test, but this error will occur when you refresh the server.
The obvious error is that the database is not closed and the resources are not released in time when datareader is used. [Generally]
As a result, the database operation class has been found, but it is obvious that all resources have been released in a timely manner. No error source is found for step-by-step tracing and debugging.
I found related problems on the Internet and found that all points point to the resource release issue.
Because the using statement is used in the logic layer to release one or more objects, return is returned.
Will it be caused by this ?!
After the results are modified and tested, you can find that the results are still correct! However, the resources found on the internet mentioned that using is playing tricks! I personally think it is unlikely!
Later, we confirmed that the using statement can be returned.
E. g:
Using (Dataset ds1 = new dataset (), ds2 = new dataset ()){}
When the return statement is used in the using statement, using can still ensure that the specified object is released.
Not only that, whether it is normalProgramWhen the stream ends, the Return Statement jumps out, or an exception is thrown, all objects within the using range can be analyzed normally.
This is a bit similar to finally, but it is more timely than finally, because you do not need to wait for the time when the garbage collection mechanism starts, but start when you exit the using statement!
ReferenceArticle:
Return within a C # using statement
While writing some code earlier today I needed to return from within a using statement. doing these sorts of things always makes me appreciate the using statement and how wonderful it really is, so I decided to write about it here. as your of you know the using statement in C # is a good tool for managing types which will be accessing unmanaged resources. some examples of these are sqlconnections, filereaders, and plenty of other similar types. the key to these is that they all implement the idisposable interface. this means that they all need to be cleaned up carefully after using them.
The Using statement is great because it guarantees that the declared object is disposed no matter how the execution completes. whether you reach the end curly brace marking the end of the using statement, throw and exception, or return from a function, the using statement will call the dispose method and clean up the object.
This was important in my code because I was able to return directly from within the using statement without worrying about whether or not eh dispose method will fire. whenever I use an object which accesses unmanaged resources I always put it in a using statement.
It is very important to use a using statement, because it will give you this guarantee that the object will be disposed of correctly. the object's scope will be for the extent of the using statement, and during the scope of the object it will be read-only if defined in the using statement. this is also very nice, because it will prevent this important object which manages the unmanaged from being modified or reassigned.
This is safe to do, because of how great the using statement is. No matter which return we hit we know the xmlreader will be disposed of correctly.
Using(Xmlreader reader = xmlreader. Create (xmlpath ))
{
//... Do some work...
If(Somecase)
Return0;
//... Do some work...
If(Someothercase)
Return1;
}
Return-1;
Link: http://aspadvice.com/blogs/name/archive/2008/05/22/Return-Within-a-C_2300_-Using-Statement.aspx
Finally, it still cannot be solved. I only moved on to the big project and processed the database connection string in singleton mode, and then serialized it.
Then I adjusted the data layer again!
The problem is finally solved!