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

Problem when reopening an SQLite connection to the same database

4 Answers 229 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.
Clement
Top achievements
Rank 1
Clement asked on 22 Nov 2012, 05:25 PM
Hello,

I am currently using OpenAccess with an SQLite connection to manage persistent storage. In my application, I'd like to have "save as" capability. If there are uncommited changes, the idea is to commit them in the new file, not in the old one.

My idea here was:
  1. copy the old database before the commit in a temp file
  2. commit the changes
  3. close the connection
  4. rename the old file to the new one
  5. rename the temp file to the old one
  6. open a connection to the new file

The problem here is that when i call dispose() on my context, the connection seems to be still up, locking the possibility to rename the old file.
As seen in another topic (http://www.telerik.com/community/forums/orm/orm-express/unable-to-delete-a-sqlite-database.aspx), I tried and set TimeoutConnection to 0. In this case, I am able to rename the files correctly and connect to the new database, so far so good. The problem occurs when I try to reconnect to the old file. In this case, the context seem to be somewhat wrong, displaying problem with "connectionUrl" empty.

Could you help me out with this ?

Thanks,

Clement.

4 Answers, 1 is accepted

Sort by
0
Accepted
Ady
Telerik team
answered on 27 Nov 2012, 08:42 AM
Hi Clement,

 OpenAccess maintains a connection pool for better performance. This means that even if you dispose a context the actual connection to the database is not closed but returned back to the connection pool. Can you try switching off OpenAccess connection pooling and switch to plain ADO connection pooling.
In case that does not help you can try completely switching off connection pooling by specifying 'pooling=false' in the connection string.
What is the exact exception you get with the connectionurl being empty? Can you send me the call stack and the code that causes this exception?

Kind regards,
Ady
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
Clement
Top achievements
Rank 1
answered on 27 Nov 2012, 09:50 AM
Hello Ady,

Thanks for your answer. I works when letting ADO managing the connection pool !

I tried it before, but letting the connectiontimeout to 0. In this case, the connectionUrl problem still happens. The solution is to set the connectionPool to ADO and that's all.

FYI, the connectionUrl problme occured when I try to reopen the database, on the call to DatabaseExists method;
var schemaHandler = _dbContext.GetSchemaHandler();
bool dbExists = schemaHandler.DatabaseExists();
The stacktrace is
L'exception System.ArgumentException n'a pas été gérée
  Message=Project without connection url can not be opened.
  Source=Telerik.OpenAccess.Runtime
  StackTrace:
       à OpenAccessRuntime.Relational.sql.SqlDriver.getNameFromURL(String url)
       à OpenAccessRuntime.Relational.RelationalConfigParser.parse(ConfigInfo config)
       à OpenAccessRuntime.DataObjects.tools.ant.DatabaseCreationTask.prepareDriver()
       à OpenAccessRuntime.DataObjects.tools.ant.DatabaseCreationTask.createDatabase()
       à OpenAccessRuntime.DataObjects.tools.ant.DatabaseCreationTask.execute()
       à OpenAccessRuntime.OpenAccessSchemaAdapter.CreateDatabase(Boolean checkOnly)
       à OpenAccessRuntime.SchemaHandlerImpl.Telerik.OpenAccess.ISchemaHandler.DatabaseExists()
       à SCE.DataLayer.sce_RepositoryManager.createDatabaseIfNotExist() dans D:\svn\working directory\viewer\sources\code\smart_city_explorer\DataLayer\sce_RepositoryManager.cs:ligne 230
       à SCE.DataLayer.sce_RepositoryManager.openProject(String file) dans D:\svn\working directory\viewer\sources\code\smart_city_explorer\DataLayer\sce_RepositoryManager.cs:ligne 130
       à SCE.Core.sce_Core.loadProject(String file) dans D:\svn\working directory\viewer\sources\code\smart_city_explorer\Core\sce_Core.Project.cs:ligne 50
       à SCE.GUI.sce_MainForm.onUserClickRecentDocument(Object sender, EventArgs e) dans D:\svn\working directory\viewer\sources\code\smart_city_explorer\GUI\sce_MainForm.cs:ligne 362
       à Telerik.WinControls.RadItem.OnClick(EventArgs e)
       à Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
       à Telerik.WinControls.UI.RadMenuItem.OnClick(EventArgs e)
       à Telerik.WinControls.RadItem.DoClick(EventArgs e)
       à Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       à Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       à Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       à Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       à Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
       à Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
       à Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
       à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       à System.Windows.Forms.Control.WndProc(Message& m)
       à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       à Telerik.WinControls.RadControl.WndProc(Message& m)
       à Telerik.WinControls.UI.RadPopupControlBase.WndProc(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       à System.Windows.Forms.Application.Run(Form mainForm)
       à SCE.Program.Main() dans D:\svn\working directory\viewer\sources\code\smart_city_explorer\Program.cs:ligne 27
       à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Thanks again for the answer,

Best regards,

Clement.
0
Clement
Top achievements
Rank 1
answered on 07 Dec 2012, 02:29 PM
To be complete, I think that disposeDatabase() should be called on the context in order for the connection to be actually closed.
0
Ady
Telerik team
answered on 12 Dec 2012, 09:13 AM
Hi Clement,

 Calling 'DisposeDatabase' disposes the underlying static Database instance. This means that the next time you try to perform any OpenAccess operation the entire metadata will be recalculated. This is an expensive operation and ideally should be performed only once, on the first operation.
Just using ADO connection pool should work.
If possible do send me a sample that demonstrates the problem with just using ADO connection pool.

All the best,
Ady
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
Data Access Free Edition
Asked by
Clement
Top achievements
Rank 1
Answers by
Ady
Telerik team
Clement
Top achievements
Rank 1
Share this question
or