Open DataBase by Windows and Mac

I have written my program on a Mac platform and its run very well.
The Program and the data base are in the same directory.

Now I like to run it on Windows 7. A have copy the program and de DataBase also in the same directory in a Windows folder, but it’s don’t run. There is always an error like:
“Database file doesn’t in exist in the specified location”

Dim DbFile as FolderItem dbFile = GetFolderItem("Bestellingen.sqlite") if DbFile <> NIL then DBase=new SQLiteDatabase DBase.DatabaseFile = dbFile DBase.MultiUser=True if DBase.Connect then Return True Else MsgBox("DataBase kan niet geopend worden. fout: " + DBase.ErrorMessage) Return False End If End If
What’s wrong ??

Maybe the App is not allowed to create a file within the Programms Folder?
What happens if the Database file is already existant?

I would recommend to put the Database into a Folder where the user has the right to do anything.

DbFile <> nil isn’t good enough. You need to check if dbfile.exists = true. So it would be something like this:

if dbFile <> nil and dbFile.Exists = true then //Open db normally. else msgbox "DbFile does not exist." end

The Dbase file exists in the same folder as the program.
But the error is always:
“Database file doesn’t in exist in the specified location”

Hi Hans,

Onderstaande folderitem verwijst naar je datababestand als dit voorkomt in dezelfde directory als je .EXE.

Specialfolder.CurrentWorkingDirectory.NativePath + strDbFileName

Let wel op, in de debugmode is dit uiteraard niet zo en zou je even een hard pad kunnnen coderen:

Ji Joost,
Bedankt, ik ga het morgen meteen uit proberen.

Hi Joost,

Ik heb het volgende geschreven, maar het funktioneerd niet, fout melding.

Dim DbFile as FolderItem Dim FileNaam As String FileNaam="Bestellingen.sqlite" DbFile = Specialfolder.CurrentWorkingDirectory.NativePath + FileNaam if DbFile <> NIL then DBase=new SQLiteDatabase DBase.DatabaseFile = dbFile DBase.MultiUser=True if DBase.Connect then Return True Else MsgBox("DataBase kan niet geopend worden. fout: " + DBase.ErrorMessage) Return False End If End If

DbFile = Specialfolder.CurrentWorkingDirectory.Child(FileNaam) would be better as it is xPlat, however on Windows current working directory is probably not writable. You might like to try Specialfolder.ApplicationData.

Now the error is: “DataBse file doesn’t exist in the specified location”
But the DataBase is in the same folder as the program !!!

2 possible reasons:

  1. Wrong Path in App
  2. No accessrights

On windows (and on Mac too!) you must use the Users’ Appdata or Document Locations for your databases or other read-writeable assets.

Hi Hans, als het databestand nog niet bestaat, dan moet het eerst worden aangemaakt.
Ik heb je code even werkend gemaakt:

[code] Dim DBase As SQLiteDatabase
Dim FileNaam As String = “Bestellingen.sqlite”
Dim Pad As String = Specialfolder.CurrentWorkingDirectory.NativePath + FileNaam

MsgBox Pad

Dim DbFile As New FolderItem(Pad,3)

If DbFile <> Nil Then
DBase = New SQLiteDatabase
DBase.DatabaseFile = DbFile
DBase.MultiUser=True

// als het databestand niet bestaat,  dan moet het hier worden aangemaakt
//  -----------------------------------------------------------------------------------
If DBase.CreateDatabaseFile Then
      // indien het bestand nog niet bestaat, dan wordt het nu aangemaakt.
     //  in dat geval moet je wel nog je tabellen etc. aanmaken nadat je verbonden bent.
End If
//  -----------------------------------------------------------------------------------

If DBase.Connect Then
  MsgBox("Database verbonden")
Else
  MsgBox("DataBase kan niet geopend worden. fout: " + DBase.ErrorMessage)
End If

End If

Break[/code]

Hi Joost,
Ook met de laatste code komt dezelfde fout melding, als ik een nieuwe DataBase maak of de oude gebruik.
Ik heb allerdings nog geen build license, kan dat mischien van invloed zijn?

I do not speak Neth.
I am out of here :slight_smile:

Every thing is still working under mac Open, read and close the database.
But by windows 7 the program can’t find the database.
Always the database is in the same folder as the program, on the windows platform and by Mac.

The Code is:

Dim DbFile as FolderItem dbFile = GetFolderItem("Bestellingen.sqlite") if DbFile <> NIL then DBase=new SQLiteDatabase DBase.DatabaseFile = dbFile DBase.MultiUser=True if DBase.Connect then Return True Else MsgBox("DataBase kan niet geopend worden. fout: " + DBase.ErrorMessage) Return False End If End If

By Mac it’s works.
By Windows there is an error like:
“Database file doesn’t in exist in the specified location”
Also if a changed the code in:

Dim DbFile as FolderItem Dim FileNaam As String FileNaam="Bestellingen.sqlite" DbFile = Specialfolder.CurrentWorkingDirectory.Child(FileNaam)

Im am working with a version without a build license, only the debugger.

@Hans Riemers : let’s continue in English:

You know how the debugger works I guess. Well, open a new empty project and copy the above code in the App.Open eventhandler and put a breakpoint on the verry first line. Walk thrue the code, line by line and tell us in which line you get an error and what the error-description is.

I tested my code in Windows 7, no problem ,
BTW: I use SQLite, MySQL and PostgreSQL in my desktop applications for Windows and Mac , the user of my application can chose at first start what he wants to use.

Maybe there is a other problem, my windows platform is on my IMac under VMware Fusion 7.1.2.

By debugging: the pad is: C:\Program Files (x86)\Xojo\Xojo 2015r24\Gestellingen.sqlite

The program file is in: C:\Daten\Dorpels\Ubung\TestDbase.xojo_binary_project

The Error by Windows is: “Database file doesn’t in exist in the specified location”