Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 966997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:14:49+00:00 2026-05-16T02:14:49+00:00

Working with MonoTouch .NET for iPhone and SQLite on Mac OSX. I can read

  • 0

Working with MonoTouch .NET for iPhone and SQLite on Mac OSX. I can read from the database no problem. However, when I attempt to make changes to the database, I get strange behavior. The code below runs without exception, but no real changes are being made to the database. I can create a table, insert a record, select that record, and display it in the console. But, when I close the db connection, all those changes go away. Further, if I put a break-point in the code before conn.Close() and check the database, the table doesn’t exist. Sounds like I’m only working with an imaginary database that responds to actual SQL statements. Weird.

This code runs but does not actually write anything to the database:

const string _connectionString = "Data Source=App_Data/MyDatabaseFile";

var conn = new SqliteConnection(_connectionString);
conn.Open();

var command = conn.CreateCommand();

command.CommandText = "CREATE TABLE Test (id integer primary key AUTOINCREMENT, text varchar(100))";
command.ExecuteNonQuery();

var cmd2 = conn.CreateCommand();
cmd2.CommandText = "INSERT INTO Test (Text) Values ('test test test')";
var rowsAffected = cmd2.ExecuteNonQuery(); //rowsAffected is 1

var cmd3 = conn.CreateCommand();
cmd3.CommandText = "SELECT * FROM Test";
var reader = cmd3.ExecuteReader();
Console.WriteLine(reader["text"]); //writes "test test test" to console, nothing in database

conn.Close();

If I execute the same SQL statements in in SQLite Browser, they work fine:

CREATE TABLE Test (id integer primary key AUTOINCREMENT, text varchar(100));
INSERT INTO Test (Text) Values ('test test test');
SELECT * FROM Test;

… yields { id = 1, text = ‘test test test’ }

You can probably tell, but it’s worth mentioning that I’m not using transactions.

UPDATE:

Interesting… I can change the code above that runs the SELECT query to look in ‘Test2’ (non-existent table) and it throws an SQLiteException: “No such table: Test2”.

I also tried wrapping the above code in a transaction on the off chance that SQLite requires transactions… no dice.

UPDATE #2:

Adam suggested trying to open a new connection and SELECT from the new table again before stopping the application. I added the following code after the above code:

var conn2 = new SqliteConnection(_connectionString);
conn2.Open();
var cmd4 = conn2.CreateCommand();
cmd4.CommandText = "SELECT * FROM Test";
var reader2 = cmd4.ExecuteReader();
Console.WriteLine("2nd attempt: " + reader2["text"]); //outputs correctly
conn.Close();

Alright, so my assumption about it losing changes after connection.Close() is incorrect. It definitely found the newly inserted row and output it to the console. However, the table and row still disappear after I stop the application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:14:50+00:00Added an answer on May 16, 2026 at 2:14 am

    For anyone dealing with the same question, I thought I’d go ahead and post my findings. The behavior I described in my original post is mostly by design. To be more clear, here’s a better explanation:

    When MonoDevelop deploys your app to the iPhone Simulator, a COPY of your SQLite database goes with it to live in the iPhone environment. So, when your app modifies your database, the original database isn’t being touched. When your app stops, the changes you made to the simulator copy of your database are lost. However, while the app is running, you can insert, update, delete and select all you want and everything should work as expected.

    This is only true when using the Simulator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a universal iPhone/iPad application. I'm using MonoTouch, but I can take
I have not been working with Monotouch (or the iphone for that matter) for
I'm trying to use the code posted here: http://seanho.posterous.com/monotouch-first-attempt-arkit-c-version however - when i try
I'm reading through the Professional iPhone Programming with MonoTouch and .NET/C# book, but I'm
I am currently porting a .NET codebase in MonoTouch and I'm currently working on
Hi im working on iphone application using monotouch im trying to get list of
I am working on a .NET app that will also run on iphone via
I'm working to an iPhone project using MonoTouch, and I need to serialize and
I need to make sure that our iPhone App (implemented with Monotouch) will still
I've read the small section about Dispose() in http://monotouch.net/Documentation/API_Design and a similar question asked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.