-1

I want to connect my application with sqlite database but it throw the exception.

An exception of type 'System.BadImageFormatException' occurred in Scrap_Book.Windows.exe but was not handled in user code

Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

        var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "scrapbook.sqlite");
        using (var db = new SQLite.SQLiteConnection(dbpath))

Second line throw exception.

I am unable to resolve it. please help me i am new in programming. Thanks in advance.

vikas sharawat
  • 217
  • 1
  • 13
  • Related http://stackoverflow.com/questions/8996653/troubleshooting-badimageformatexception – Sanket Jul 30 '16 at 10:57
  • I install sqlite-net package – vikas sharawat Jul 30 '16 at 11:15
  • which added two class in my project Sqlite.cs and SQLiteAsync.cs and exception occurs in SQlite.cs – vikas sharawat Jul 30 '16 at 11:17
  • 1
    A package added .cs files? That's odd. Better check again, and add very precise info about which package you added. There are a lot of similar looking packages for sqlite/uwp .You should probably be using __sqlite-net-pcl__ . – H H Jul 30 '16 at 21:19

1 Answers1

0

I install sqlite-net package.

@Henk was right, you installed a wrong package for UWP app, what you need is SQLite.Net-PCL package. And for connection, you can code for example like this:

using (var db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), Path.Combine(ApplicationData.Current.LocalFolder.Path, "scrapbook.sqlite")))
{
    //TODO:
}

and don't forget, your project will also need to reference to SQLite for Universal App Platform.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45