Data sometimes not saving on Macs

Hi. I have had some of my Mac users (very few) report to me that their program is not working properly. For example, I have a start screen where a user needs to add their name to the list to keep track of their progress. I have a textbox for them to enter their name, and a button that saves their names to a table (SQLite). Their name is then populated into a listbox for them to choose. For a user who is experiencing this problem, they enter their name, click the button, but their name does not appear in the listbox, and I’ve confirmed that the data is not being saved as I have had some of them send me the file, and I opened it myself to find it is blank. There are many Mac users that are using the program and have no issues. Also I’ve never had any Windows users report any problems with saving data, so I know the feature is working properly. It’s only a very few Mac users.

Are there any settings on Mac machines that might prevent saving the data? I’m stumped.

I have a snippet of my save method below

[code] 'saves data into user table
Dim dr as new DatabaseRecord

dr.Column("userName") = trim(txtNew.Text)

dbUser.InsertRecord "users", dr
dbUser.Commit[/code]

Are you checking dbUser.Error and ErrorMessage after doing the InsertRecord? Perhaps the DB is read-only? Where is the DB file stored?

I agree with Paul, How do you know the user is not using a character which would throw an error.

Try putting a username FOO’s USERNAME with the apostrophe. I bet this throws the error.

Thanks guys. The database is stored on the Mac HD, under Library, then in a new folder I created during the installation. They have the folder and files in here from the installation but I am just having them manually replacing the db with one I add their name to and send them.

As far as errors, I do not have any error checks but will add them now. The girl who had this issue last night was entering “Jasmine” with no punctuation.

This table isn’t read-only as there have been other Mac and Win users who have been able to store their names into the table. Is there a problem with the db being stored in the Mac HD? Would you have another suggestion as to where a good place to store a db on a Mac? On Win, I install the dbs in the Documents folder

Which Library folder? The system Library at the root (/Library) or the user’s Library folder (~/Library)?

Write permissions might not be available, depending on the type of user (Admin or not) and other factors.

Generally speaking, your own folder within Application Support is best for behind-the-scenes data: SpecialFolder.ApplicationData

For user documents, just let the user choose the file and save it where they want.

Ok that makes sense Paul, thank you. I think it would be the root Library where it is stored.

I think I’ll go ahead and set it up to save the data in the Special Folder as you mentioned.

Thanks for your help!

I’m a little confused on where to call the db in the code when the app opens. Testing this out with a dummy app. Could you comment on this?

dbFile = SpecialFolder.ApplicationData.Child("Library").Child("Application Support").Child("Visual Veggies Data").Child("codes.sqlite")

Also tried

dbFile = SpecialFolder.ApplicationData.Child("Visual Veggies Data").Child("codes.sqlite")

I use:


  Dim f as FolderItem
  
  f = SpecialFolder.ApplicationData.Child(app.kBundleIdentifier)
  
  f.CreateAsFolder
  
  f = SpecialFolder.ApplicationData.Child(app.kBundleIdentifier).Child(app.kBundleIdentifier + ".sqlite3")
  
MyDatabase.DatabaseFile = f

Where MyDatabase is an SQLiteDatabase. kBundleIdentifier is just my bundle identifier stored as a constant in my App class. I have a bit more code so I don’t overwrite my db if it already exists (unless you want to)

But isn’t my example below virtually the same? I’m creating the folder and including the db all in my installer.

dbFile = SpecialFolder.ApplicationData.Child("Visual Veggies Data").Child("codes.sqlite")

Does the above point to Mac HD > Library > Application Support > Visual Veggies Data > codes.sqlite

I’m using Packages to create my install files, and it doesn’t look like many options to store files other than in Library, which seems to be the Library in the hard drive

[quote=22315:@Ryan Hartz]But isn’t my example below virtually the same? I’m creating the folder and including the db all in my installer.

dbFile = SpecialFolder.ApplicationData.Child(“Visual Veggies Data”).Child(“codes.sqlite”)
Does the above point to Mac HD > Library > Application Support > Visual Veggies Data > codes.sqlite

[/quote]

No, this points to Mac HD > User > Library > Application Support > Visual Veggies Data > codes.sqlite.

It points to the Library in the User’s account, which is the one you want because it is the one where you will have write permissions.

If your installer cannot put the file there for you, then you can instead include it in the Resource folder of the App bundle and then copy it where it needs to be when your app first runs.

Does sandboxing allow this? I guess it would if you are not changing the resource folder just copying something out of it?

Good question. I think it is OK, but I do not know for certain.

Ryan, are you needing to install your db when you install your app? Is the db empty or does it come pre-loaded with data. I have an InitDB method which I call when my app opens if the db does not exist in the users application support folder I create it from scratch rather than copy anything into it. If the db is already there InitDB just exits.

Thanks Mike and Paul.

Mike - I do need to install the dbs when I install the app. There are actually 2 databases I need to include. One is an exam database preloaded with questions, answers, and such, and the other is a blank users database. This program is sometimes used at colleges where there could be several students accessing the program on the computer. The users db makes the student add then choose their name in the box, and their individual progress is kept track in this db. So I have a need for both. I wonder if you are leading me to using the initDB method for the blank one, and then the read-only preloaded db can just sit in the Library folder as it has been?

Mmm I wouldn’t bother if you need to copy one pre-loaded db you may as well copy both.

Do you mean there may be many users connected to the one database? If so I don’t think the ApplicationData folder will work for you unless all the users are logged on as the same user.

Also I am not sure how SQLite handles multiple concurrent calls to the database, this might be your problem.

No, sorry about that. I have it so the schools can only install onto one computer and create a general login for the students. There could be several students using the program, but only one at a time

I suspect it is back to Paul’s idea then that you need to install in the users ApplicationSupport folder not the system due to read/write access.

Thanks for your help guys. I think I got it figured out. I tested it on my machine, and it seems to be workng well. I am waiting to hear back from the user who recently notified me.

I do have a question about where this data is stored. How do you navigate to the folder I specified? I looked in Library > Application Support, but did not see my folder I included there. I don’t know why I’d ever need to navigate to the db files, but as I have in the past, I sometimes had to have a user drop in the db file if it did not install properly. Just trying to be prepared, and I guess, curious :slight_smile:

In finder Hold down the alt key and while holding it click on the go menu and you will see a menu called library, click on it and application support is in there. (I am not at my mac while writing this so it’s off the top of my head but I’m sure that’s right)

Unfortunately, the user Library folder is hidden in Finder by default starting with OS X Lion (10.7). You can get to it by using Go to Folder (in the Go menu) and entering “~/Library”. You can also permanently unhide it with this terminal command:

chflags nohidden ~/Library/

You’ll have to re-apply that after any OS X updates, though.

The equivalent folder (AppData) is also hidden on Windows.