Problem with SQLite on iOS

Hi, I’m facing an issue with SQLite on iOS. It used to work fine some time ago, and it still works flawlessly on Android. However, on iOS, I’m encountering a connection problem. Has anyone else experienced a similar issue recently? I would greatly appreciate any insights or suggestions.

  string dbPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            dbPath = Path.Combine(dbPath, "highscoredata.sqlite");
            _database = new SQLiteAsyncConnection(dbPath);
           _database.CreateTableAsync<HighScore2>().Wait();
public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            //Content.RootDirectory = "Content";
            Content.RootDirectory = "Content/bin/iOS/Content/";
            _graphics.IsFullScreen = true;
            graphics.PreferredBackBufferWidth = ScreenWidth;
             graphics.PreferredBackBufferHeight = ScreenHeight;
            _graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            _graphics.ApplyChanges();
            //high score version sqlite
            _highScores = new HighScoreDataStore(); 

        }

Thank you in advance for your help.

Here’s how I’ve always gotten db path on iOS, this should work on both physical device and simulator:

string dbPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
dbPath = Path.Combine(dbPath, Assembly.GetEntryAssembly().GetName().Name);
dbPath = Path.Combine(dbPath, dbName);
if (!Directory.Exists(dbPath))
{
	Directory.CreateDirectory(dbPath);
}

Hope this helps. Cheers!

1 Like

Hi,
great thanks for your help :grinning: i will try that

Hi, I just tested it in debug mode and I’m getting this error: 'Exception of type
Exception of type 'Mono.Debugger.Soft.VMDisconnectedException' was thrown.

Hi, Thank you again for your help :grinning:.
I found the solution. The problem wasn’t in the code but in the sqlite-net-pcl version. You need to add these packages to the .csproj file. When you import the latest version of SQLite, the packages associated with it may not be the latest versions.

<PackageReference Include="sqlite-net-pcl" Version="1.8.116" /> 
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" /> 
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />

I hope this helps :grinning:.