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

Unable to delete a sqlite database

1 Answer 73 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Krasimir
Top achievements
Rank 1
Krasimir asked on 19 Mar 2011, 10:47 AM

Hello guys!

I have a not very big, but frustrating problem. I am working with sqlite databases and I do some simple operations like retrieving collection of instances of domain model types. I'm doing it in this fashion : 


public List<T> FindAll()
       {
           ProgramsModel context = ContextProvider.GetProgramsContext();
 
           using (context)
           {
               return context.GetAll<T>().ToList();
                
           }
       }
public class ContextProvider
    {
  
        public static string ProgramsConnectionString { get; set; }
        public static string DllPath { get; set; }
  
        public static ProgramsModel InitProgramsContext()
        {
           
            XmlMetadataSource metadataSource =
                XmlMetadataSource.FromAssemblyResource(Assembly.LoadFrom(
                    DllPath + "BanTester.Repositories.dll"), "ProgramModel.rlinq");
            BackendConfiguration backendConfiguration =
                new BackendConfiguration {Backend = "sqlite"};
  
            return new ProgramsModel(
                ProgramsConnectionString, backendConfiguration, metadataSource);
            
        }
  
        public static ProgramsModel GetProgramsContext()
        {
          return InitProgramsContext();
        }
  
    }

In the first line of the method body I'm initializing a new OpenAccessContext manually (Connection sting, metadata, backend). 

So, I am successful with this operation, but I was counting that with disposing the context the connection to the database will be closed.

And here is the problem : when trying to delete the database I'am receiving an exception that the file is used by another process. I am pretty sure that other parts of my application are not keeping a handle to the file. Can you give me directions to where the problem might be?

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 21 Mar 2011, 09:56 AM
Hi Krasimir,

I think there are actually two problems here: First is the access to the instances managed by an already disposed context (return from within the using statement) and the second is that the underlying database is not closed synchronously.
We are working on the first issue as it seems that some customers use this style of programming.  
For the second issue, there the ConnectionTimeout on the BackendConfiguration has to be set to a value of zero prior to the opening of the first context. This will ensure that the Dispose of the context will lead to the closing of the underlying database.

All the best,
Thomas
the Telerik team
Tags
Data Access Free Edition
Asked by
Krasimir
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or