# Sqlite connection help

**URL:** <https://forum.xojo.com/t/sqlite-connection-help/86490>\
**Category:** Databases\
**Created:** [September 12, 2025, 3:49am UTC](https://forum.xojo.com/t/sqlite-connection-help/86490 "2025-09-12T03:49:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 12, 2025, 3:49am UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/1 "2025-09-12T03:49:39Z")

</div>

hi!

i’m confused…

why i need to declare every time this code even after make the mySQLiteDB as a global property?

```auto
Var mySQLiteDB As New SQLiteDatabase
Var mySQLiteDBFile As FolderItem = GetFolderItem("").child("Contents").child("Resources").child("FatCatDB.sqlite")
If mySQLiteDBFile <> Nil And mySQLiteDBFile.Exists Then
  mySQLiteDB.DatabaseFile = mySQLiteDBFile
  mySQLiteDB.Connect
End If

```

if i remove the first line, (and declare it on “app.open”) the code runs, no error. but **i can’t insert** on database file, **only read from it!**  
why?

i just want to put it all on “app.open” and keep the sqlite connected, until i close it.

why i can’t just do it at “app.open” and keep the db open just like mysql?

* * *

mySQLiteDB is on a module

i have this on my app.opening:

```auto
mySQLiteDB = New SQLiteDatabase
openFatCatDB()

```

the openFatCatDB is:

```auto
#If (TargetMacOS Or TargetWindows Or TargetLinux) And DebugBuild Then
  
  mySQLiteDB.DatabaseFile = SpecialFolder.Resources.Child("FatCatDB.sqlite")
  mySQLiteDB.Connect

```

… etc

i can’t do any insert anywhere. ONLY if i put this before the insert code…

```auto
Var mySQLiteDB As New SQLiteDatabase
Var mySQLiteDBFile As FolderItem = GetFolderItem("").child("Contents").child("Resources").child("FatCatDB.sqlite")
If mySQLiteDBFile <> Nil And mySQLiteDBFile.Exists Then
  mySQLiteDB.DatabaseFile = mySQLiteDBFile
  mySQLiteDB.Connect
End If

```

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 12, 2025, 6:00am UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/2 "2025-09-12T06:00:40Z")

</div>

Please don’t open a database from app resources. Consider the app itself to be read only. Depending on the computer, you may not have write permissions there. And changing the app bundle would break code signature.

Better make a copy of the database to the application data, preferences or documents folder. And then open it there.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 12, 2025, 9:37am UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/3 "2025-09-12T09:37:59Z")

</div>

> [@Alexandre\_Cunha](#):
>
> why i need to declare every time this code even after make the mySQLiteDB as a global property?
> 
> `Var mySQLiteDB As New SQLiteDatabase`

VAR created variables ARE NOT GLOBAL PROPERTY.

Add a New Module (if your project does not already have one) and add there a SQLiteDatabase Property. Be sure it is Global there.

Also, avoid .Child as you use (more than one in a line): you never know who is Nil (because you cannot test those .Child). Use instead as needed lines and test each result after that line.

At last as Christian says, use [SpécialFolder](https://documentation.xojo.com/api/files/specialfolder.html).ApplicationData: create a Folder there using your app signature (com.alexandre.cunha for example), then you are on your own.

Is it clear enough ?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 12, 2025, 4:04pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/4 "2025-09-12T16:04:50Z")

</div>

ok. understood. when i publish to apple, the place are changed.

but this is not the problem. the problem is why i need to always use:

```auto
Var mySQLiteDB As New SQLiteDatabase

```

and i can’t use it as a global property!

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 12, 2025, 4:07pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/5 "2025-09-12T16:07:31Z")

</div>

did you read what i wrote?

**\> mySQLiteDB is on a module**

it does not work unless i use: Var mySQLiteDB As New SQLiteDatabase

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [September 12, 2025, 4:20pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/6 "2025-09-12T16:20:58Z")

</div>

> [@Alexandre\_Cunha](#):
>
> it does not work unless i use: Var mySQLiteDB As New SQLiteDatabase

Create a sample project, zip it, upload to this thread.  
People will be able to tell you what to change.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 12, 2025, 9:44pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/7 "2025-09-12T21:44:25Z")

</div>

i’m doing some tests with a new empty project.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [September 12, 2025, 11:45pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/8 "2025-09-12T23:45:58Z")

</div>

> [@Alexandre\_Cunha](#):
>
> but this is not the problem. the problem is why i need to always use:
> 
> ```auto
> Var mySQLiteDB As New SQLiteDatabase
> 
> ```
> 
> and i can’t use it as a global property!

Because Var creates a new local variable which is closer in scope, so it gets used instead of the global property. You simply need

```auto
mySQLiteDB = New SQLiteDatabase

```

somewhere in your initialization code.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 13, 2025, 2:47pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/9 "2025-09-13T14:47:47Z")

</div>

hum…

i think i did a mess with 2 databases. i’m checking all and doing some tests.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 13, 2025, 3:46pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/10 "2025-09-13T15:46:34Z")

</div>

When I have to deal with SQLite Data base, I go to [Database Basics](https://documentation.xojo.com/topics/databases/database_basics_for_beginners.html#database-basics-for-beginners)

That page have changed since the last time I get there…

And so, a better page for your case is: [SQLite → Overview](https://documentation.xojo.com/topics/databases/supported_engines/sqlite/overview.html)

Provides better sample code, etc.

There is/are examples in the Examples folder you can download from the IDE (New → Examples → Download).

At last, yes, I read what you wrote and the trouble lies there:

Var properties are active within the Code you wrote that line;

Module properties can be active through your application; and as someone wrote, using both is like having two drivers in your car: this does not works properly (as you experiment). Conflict of interest ☹ one cannot work for him when in his boss enterprise (shop, whatever; while at work).

Yes, in some cases, a Property in a Module needs extra work to be active as with SQLiteDatabase (and FolderItem, etc.).

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 14, 2025, 3:47pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/11 "2025-09-14T15:47:10Z")

</div>

I think It was a bug on IDE. it was not reading the new row after adding using global database variable.

i quit and reopen IDE and it’s working again.

i’m checking all again and trying to force the bug again.

thank you all for the help.

now my insert method is only this, and it’s working properly.

 ![image](https://forum.xojo.com/uploads/default/original/3X/2/9/2937c91c0b4f248145b901262584a7ecab414a67.jpeg)

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 14, 2025, 4:33pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/12 "2025-09-14T16:33:51Z")

</div>

Did you move your data base file from inside of your application bundle ? (Resources)

```auto
Var mySQLiteDB As New SQLiteDatabase
Try
  Var newRow As New DatabaseRow
  newRow.Column("name").StringValue = "name"
  newRow.Column ("dataHora").StringValue = "dataHora"
  newRow.Column ("level") .StringValue = "level"
  newRow.Column ("recordTime") .StringValue = "recordTime"
  mySQLiteDB.AddRow ("record", newRow)
Catch err As DatabaseException
  MessageBox("Error: " + err.Message)
End Try

```

To be able to do the above (instead of a screen shot), click first in  
 ![image](https://forum.xojo.com/uploads/default/original/3X/0/e/0e434d3800e5ff22f9fe197e13083facf3d8b7aa.png) then paste your code, select your Pasted code and click in  
 ![image](https://forum.xojo.com/uploads/default/original/3X/4/9/4923875b0f637114eb1b62a3b48939dbb69306e5.png)

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 14, 2025, 6:49pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/13 "2025-09-14T18:49:39Z")

</div>

Try this example, and look at the used code…

[Currency in SQLite.zip](https://forum.xojo.com/uploads/short-url/aJamOUyOEktNMj2XWHEIg9uPmrp.zip) (11.0 KB)

1. I already shared this example (I wrote it for someone else)
2. Once you run it, click in  
Create  
Import (and choose the provided text file)  
Read (to display the data)  
Eventualy Tag Debut (to display the date as SQLDate stored in RowTag).

You can click in the first column to sort the entries by dates (if you cliked in the “Tag Debug” button).

Or simply ignore this entry: your choice.

PS: the .sqlite file is saved in the project folder, it was just an example.

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 14, 2025, 9:03pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/14 "2025-09-14T21:03:49Z")

</div>

> [@Emile\_Schwarz](#):
>
> Did you move your data base file from inside of your application bundle ? (Resources)

no. it was always outside

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 15, 2025, 3:25pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/15 "2025-09-15T15:25:46Z")

</div>

> [@Alexandre\_Cunha](#):
>
> `Var mySQLiteDBFile As FolderItem = GetFolderItem("").child("Contents").child("Resources").child("FatCatDB.sqlite")`

And your code above do not save the database INSIDE your Application ?

PS: I am not an AI, I may made mistakes, but usually, I do not hallucinate 😉

---

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [September 15, 2025, 5:53pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/16 "2025-09-15T17:53:14Z")

</div>

sorry. inside. but this was not the problem.

I think It was a bug on IDE. it was not reading the new row after adding using global database variable.

i quit and reopen IDE and it’s working again.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [September 15, 2025, 6:57pm UTC](https://forum.xojo.com/t/sqlite-connection-help/86490/17 "2025-09-15T18:57:29Z")

</div>

And how runs my example in your computer ?
