Unable to delete a sqlite database

2 posts, 0 answers
  1. Krasimir
    Krasimir avatar
    6 posts
    Member since:
    May 2009

    Posted 19 Mar 2011 Link to this post

    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 =
                        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?

  2. Thomas
    Thomas avatar
    588 posts

    Posted 21 Mar 2011 Link to this post

    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,
    the Telerik team
  3. DevCraft banner
Back to Top