This file is not a database error

I am getting this error since yesterday and after having fixed this this morning, again I am getting it just now, even though the app was running normally last night and after I fixed it this morning. Why do I get this error?

What a strange way to open a file.

Set a file type and the user (you) cannot open any file / can open only .sqlite files.

Watch for FileTypeGroup in the Documentation

File Type Group Editor

https://documentation.xojo.com/api/user_interface/desktop/openfiledialog.html#openfiledialog


Sub ChooseDatabase()
//Get the file name
Var dig as new OpenFileDialog
dlg.Title = "Open *.sqlite File"
f= dlg.ShowModal
//Connect to a SQLite database
db = new SQLiteDatabase

Are-you able to Cancel at this stage ? or must you force quit ?

I can cancel normally. I never experienced this problem before. Why is this a strange way to open a file? I don’t understand? The database is being connected from the File menu (open item). Isn’t that supposed to be this way? I am looking at the File Type Group Editor
 not sure what I am looking at here
 :slight_smile:

You do not add a File Filter to the Dialog that let me think you are able to open ,any file and pass its reference to the Data Base and get what you say.

Add a File Type to your project, add it to the Dlg.Filter and you will no more be able to select an image file (or anything else excepted a folder) instead of a .sqlite file.

More


OpenFileDialog.Filter
https://documentation.xojo.com/api/user_interface/desktop/openfiledialog.html#openfiledialog-filter

An example earlier in the page does not use it on purpose, but it is an error IMHO. The example allow to select any file but new comers may understand it wrongly.

You may read the book:

Introduction to Programming with Xojo

Also, in your screen shot, you wrote:
In case of DatabaseException re-run ChooseDataBase


This looks to me like an infinite loop if there is a DatabaseException.

Wrong. In the screen shot, you ask the user to select a file:

f= dlg.ShowModal

I notice that I was calling the database from 3 different places. I removed those codes and only left the one in the File menu/Open item. Now everything works normally again.

I will read the documentation on the File Group Editor although right now, I have no idea what its function is.

How did you fix it this morning?
Are you sure you are selecting a file that is a database?

Edit: ok, it looks like you found the problem.

File Type Group allow you to set an object that will be used as a file filter in the Open Dialog (not only).

You use in your screen shot “.sqlite”.

.sqlite is set in a File Type you have created using the File Type Editor.

As I already wrote earlier, if you do not set a filter (using a FileType Reference), you will be able to select an image or a binary file isntead of a .sqlite file.

http://www.xojo.com/learn

1 Like

This morning I fixed it by going back to a version from 3 days ago and made all the changes I had done after that up till this morning. I save every evening a new version in its own folder for save keeping. But I have no idea what this error happened accept maybe it is because I was trying to open the database file from 3 different places.

He remove the problem, but I do not know if this is a definitive removal or
 it depends on what he removed.

I’m sorry, I don’t understand this. The code you show on the first post is supposed to open a dialog so the user can select a file.
Do you want the user to select the database file?

Yes, that is what I thought is supposed to happen when you open a program. For example a word processor or other apps. You open a program and from the file menu, you open the file you are working on. I start to get the feeling that this isn’t the right way of doing it 
 :slight_smile: From the File Menu / Open, I run the Method “Open File” and in this method I run these methods:

ChooseDatabase
RefreshStoryListbox
RefreshCharacterListbox
LoadArchetypePopup

Is this datebase file one that is a user database so the user should choose it like they choose a Word doc, or is it a database file that’s private to your app from which you read app data and the user shouldn’t know about it?

It’s a db file that the user is able to choose and can save where he wants (although that part I still have to code). It’s not suppose to be a hidden DB file.

OK, then having it in the File menu in the menu handler for File → Open is the right place for it. But, unless you are using threads and need to open it from within a thread, you only need to open it once and then use the handle from all over the app. So db needs to be a window property (for example) so you can use it from anywhere.

FWIW, this error can happen if you are trying to open an encrypted database without the correct password.

Also, a db file doesn’t have to end with the sqlite extension. If you are allowing your user to set or create the file names at time of save, then using a file type to define what can be opened might be problematic. You should make sure on the save you enforce some type of file extension rule.

This is especially true if you intend to open sqlite database files created in other applications than your own.

Or indeed any extension at all. I don’t use extensions on any of my SQLite databases.

i use extension
.Xojo.sqlite ← can be open with DB Browser for SQLite
.Xojo.sqlite.backup
so i know it belongs to a xojo project.