none
Publishing an WPF app which use sqlite database and entity framework RRS feed

  • Question

  • Hi,

    I've a WPF app with sqlite database. The app works great on my local machine on my local machine but when i run it on other machine it throws the following error.

    System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SQLite.SQLiteException: SQLite error
    no such table: CustDetails
       at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
       at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
       at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
       at System.Data.SQLite.SQLiteDataReader.NextResult()
       at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
       at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       --- End of inner exception stack trace ---
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
       at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
       at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
       at SqlLiteDatabase.List.Window_Loaded(Object sender, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
       at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
       at MS.Internal.LoadedOrUnloadedOperation.DoWork()
       at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
       at System.Windows.Interop.HwndTarget.OnResize()
       at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Window.ShowHelper(Object booleanBox)
       at System.Windows.Window.Show()
       at System.Windows.Window.ShowDialog()
       at SqlLiteDatabase.MainWindow.button1_Click(Object sender, RoutedEventArgs e)
    

    My app.confiig connection is string is

    <connectionStrings>
    <add name="CustomersEntities" connectionString="metadata=res://*/SqlLiteDemoModel.csdl|res://*/SqlLiteDemoModel.ssdl|res://*/SqlLiteDemoModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;|DataDirectory|Customers&quot;'" providerName="System.Data.EntityClient" />
    </connectionStrings>

    Also I've set following properties of the database:

    Build Action: None

    Copy to output directory: Copy Always

    So what could be the problem?

    Why is it that the database is found but the tables aren't created when i publish and run on other machine?

    Please help..

    • Moved by Sheldon _Xiao Wednesday, November 7, 2012 8:04 AM (From:Windows Presentation Foundation (WPF))
    Friday, November 2, 2012 9:42 AM

Answers

All replies

  • I take it you checked the table is definitely in the file you distribute?

    Do you install System.Data.SQLite.DLL ?

    and

    Is your connectionstring definitely pointing to the correct folder?

    I think you just need the name of the database  if it's in the same folder.

    So "Data Source=mydatabase.db" refers to mydatabase in the same folder as the exe.

    None of this is wpf, hence few responses.


    Friday, November 2, 2012 11:28 AM
    Moderator
  • Sorry but can you please elaborate?

    Yes i did install System.Data.SQLite.DLL. It wouldn't have worked on development machine if I hadn't.

    The above code works perfectly on my development pc..

    Do you have a better way of having sqlite database local to the application please let me know. i.e. if i publish the app, database should be a part of it.


    Friday, November 2, 2012 12:10 PM
  • Hi gojhaled89,

    If you want to deploy your dabase file, you need to set build action to Content. Data files such as SQL Database (.mdf and .mdb) files and XML files will be marked as data files by default.

    You can check the deploy files in Application Files dialog.

    To specify files published by clickonce, you should read the document below.

    http://msdn.microsoft.com/en-us/library/kzy0fky2(v=vs.100).aspx

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 7, 2012 7:56 AM
    Moderator
  • Bob,

    I've named my database file as customers but that file doesn't show up Application Files dialog box to make it as a Data File.

    Instead SqliteDatabase.pdb shows up(SqliteDatabase being my project name). I made it as Data File and tried running on other machine.

    Same problem persists. I get the same error as mentioned in my post.

    If you could send me a sample WPF application which uses sqlite and entity framework, that would be very helpful.

    Thursday, November 8, 2012 10:20 AM
  • Hi gojhaled89,

    I can't make a sample with sqlite since it is a third party product.

    I'm not sure why would you rename your database file and .pdb file is used to debug.What you should to do is

    1. right click the database file, set Build Action property to Content.

    2. set Copy to output directory to Copy Always.

    3. Right Click the project-> Properties Windows -> publish tab-> Application Files. Check if the database exist, if it doesn't, then check "Show all files" and include the databse.

    Best Rgards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, November 9, 2012 7:33 AM
    Moderator
  • My understanding is that sqlite uses a .db file extension.

    As Bob says, you need to include the database file in your solution.

    Your connection string also has to point to the location it will be installed to.

    When you install your application on some other machine, you're going to need the sqlite dll on it.  You need to distribute it in the install.

    Fail to do that and your app will run on your own machine but fail on the target.


    Saturday, November 10, 2012 3:44 PM
    Moderator