locked
Sqlite.Net db file not creating RRS feed

  • Question

  • User392521 posted

    In my project am using sqlite its working fine in debug mode when coming to release mode its not working. In release mode db file not creating.

        public static void GetDBFile(string dbPath, ISQLitePlatform sqlitePlatform)
        {
            if (dbUtils == null)
            {
                dbUtils = new DataAccess(sqlitePlatform, dbPath);
            }
        }
    

    I written like this in App.xaml.cs file calling this method in Mainactivity.cs ( Android project )

            dbPath = FileAccessHelper.GetLocalFilePath("dbfilename.sqlite");
        App.GetDBFile(dbPath, new SQLitePlatformAndroidN());
    
    Sunday, April 26, 2020 10:51 AM

Answers

  • User392521 posted

    @ShantimohanElchuri Thankyou. Just added Mono.Data.sqlite at linker ignore assemblies. It's resolved my error.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 1, 2020 1:59 PM

All replies

  • User42522 posted

    @jagdeeshk Can you give the code of the constructor of the class DataAccess?

    Sunday, April 26, 2020 12:48 PM
  • User392521 posted

    DataAccess> @ShantimohanElchuri said:

    @jagdeeshk Can you give the code of the constructor of the class DataAccess?

    DataAccess.cs

        private SQLiteAsyncConnection dbConn;
    
        public DataAccess(ISQLitePlatform sqlitePlatform, string dbPath)
        {
            try
            {
                if (dbConn == null)
                {
                    var connectionWithLock = new SQLiteConnectionWithLock(sqlitePlatform, new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: false));
    
                    dbConn = new SQLiteAsyncConnection(()=>connectionWithLock);
                    dbConn.CreateTableAsync<TableOne>();
                    dbConn.CreateTableAsync<TableTwo>();
    
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    
    Sunday, April 26, 2020 1:44 PM
  • User42522 posted

    @jagdeeshk It seems you are working on a old PCL project, is it not? If so probably I will not be able help you much. I am using current Xamarin Forms templates and in this the code is much simpler as below:

            public MyDbOps(string dbPath)
            {
                dbConn = new SQLiteAsyncConnection(dbPath);
                dbConn.CreateTableAsync<ToDoPlusItem>().Wait();
            }
    

    I am using NuGet package "sqlite-net-pcl" by Frank A. Krueger. Long time back I moved out of PCL projects. In the current setup, I tried to use the following line from your code:

    var connectionWithLock = new SQLiteConnectionWithLock(sqlitePlatform, new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: false));
    

    But it is flagging an error that the SQLiteConnectionWithLock doesn't have a constructor that takes two arguments. So the following code is valid here.

    var conn = new SQLiteConnectionWithLock(new SQLiteConnectionString(dbPath, false));
    

    Since it worked fine in Debug but not working in Release mode, now you have to check if you have set any of the project properties in Debug mode to make it work specifically. Many of the properties are to be set separately for Debug and Release modes.

    Since you are using connection string, are you connecting to an external server and not to an embedded SQLite database?

    Sunday, April 26, 2020 2:31 PM
  • User392521 posted

    @ShantimohanElchuri Thankyou. Just added Mono.Data.sqlite at linker ignore assemblies. It's resolved my error.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 1, 2020 1:59 PM
  • User42522 posted

    @jagdeeshk said: @ShantimohanElchuri Thankyou. Just added Mono.Data.sqlite at linker ignore assemblies. It's resolved my error.

    That's for Android. Did you do the same for iOS too?

    Mark your post as Answer for the benefit of others.

    Friday, May 1, 2020 2:39 PM
  • User392521 posted

    Present I am working on only android part, I have no idea about iOS.

    Friday, May 1, 2020 3:06 PM