Using Settings.settings or a SQL database? - c#

I am learning C# using Visual Studio and I am running into some issues.
I am developing a Windows form application. The application is meant to track user's running stats.
In settings: they select how many days they run and for each day they add their workout (ie: 1: 100m sprints 2: 50m sprints 3: Run a mile).
Then in the main windows form the user will be able to add their times and save it. Meanwhile a graph is projected of their times- this will allow the user to track their progress.
My question is where should I store their times? Right now I store all settings in the settings.settings doc. For the times should I use the settings file or a SQL database of some sort?

SqlCE or SQLite or any other simple inproc database will be better than Settings file.
Settings are not meant to grow with every user input, this is a task for a database, also it will be much easier to query your data using SQL.
Answering your question in comments:
There is a difference between user data and user preferences. You have to decide which is what in your app.
I would go with Settings file with everything regarding user preferences. Like form layout, colors, sounds, window size and so on.
Since Settings managing framework is pretty sophisticated, you will save yourself some time designing tables for user preferences and developing access to that tables.
Another possibly bright side of Settings file - it can be edited manually with text editor.

It is not possible to answer you without a lot more information about what a "user's running stats" is and how it is used. I can give a few general guidelines, though.
System.Configuration.ApplicationSettings are designed for customizing an application for a specific user; for example, what language the user wants the application to use, where he wants windows to appear, or default values. Settings are part of the application; they are created when the application is installed and deleted when the application is uninstalled. If multiple users run the application, each typically gets their own settings. You typically define settings when you create the application and users never add or remove them.
Databases are used to persist user data. They are typically not tied to a specific user or application; users add the data, which is available to other users or applications. Applications typically aren't installed with all user data, nor is user data deleted when the application is uninstalled.
SQL databases are used for relational data; data that has internal structure, like "all users must have exactly one address", or "any user may have zero or more phone numbers". If your data is not relational you do not need a relational database.
These are general guidelines, specific applications may do things differently for specific purposes. If you tell us more about your application we will be able to provide more specific information.

Related

best way to store strings outside of a program?

I'm currently working on a winforms application that gets information from a user via a textbox. Since this information is not likely to change very often, I would like my application to save the input and load it into the appropriate text box the next time it is run.
I feel confident in my ability to set this up on the form side of things, my question has to do with how to store the values outside of the program. My first instinct is to just use a text file, but the overhead needed to handle IO and reading in the values seems a bit much. I also would rather not have the user editing it outside of the textbox in the program. I tried using string resources, but those are read only. Is there a more elegant solution available?
You need at least a mediocre database client whether it be sql server, mdf, MS Access, SharePoint, Oracle etc. Sounds like a vis studio prog. (winforms). They are designed for IO procedures but requires data architecture knowledge or relational dbs. (RMDBS). Try a lightswitch project (if a VS proj.) to get the basics of db and form data relationships.
I know it's not outside Your program, but you could try settings, it's easy, kinda like the resources ownly in the settings you can change it.
To change settings goto:
Properties and then double click Settings, here you van add strings, bools etc. Make sure you set them to user
To access them through code use:
Properties.Settings.Default.
To save the settings use:
Properties.Settings.Default.Save()

Windows Store App Saving State Information

I'm just starting to work with windows 8 development (using c#), and am working on porting one of my applications to a windows store app. Essentially my application takes a user input string, calculates an appropriate output, and responds to the user. So I'm using a list view to track the "conversation." I display the user's input as a list view element and then display the output as the next element (using text blocks with formatting like color...).
What I would like to do is make this "conversation" persist once the app is terminated but am not sure the best way to do this. My first thought was to serialize the list view object on suspension then deserialize it on load, but the listview isn't serializable...So my next thought was to write out each input and output string to a file and try to rebuild the listview from these strings when I load the application, but I am having some issues with this as well.
So I'm curious as to what the best way to go about this is. I would like the application to start back up with the previous conversation already displayed with the same formatting and what not. Does anyone have any ideas?
I wouldn't persist the ListView anyway, you only need to persist the data in it. Are you using a MVVM type model, where your conversation is perhaps captured as an ObservableCollection and then bound to the ListView? If not, you should :)
Then you'd just need to serialize the ObservableCollection (see one option for that here). Where you persist it kind of depends on you:
LocalFolder would use a file based approach and be available on the local device
RoamingFolder would also use a file based approach but sync using the cloud across multiple devices that the user owns (and has the app installed)
Cloud storage (like Windows Azure or Windows Azure Mobile Services) would provide essentially boundless storage for you, but requires managing a cloud account and paying for it (though free tiers may be sufficient)
An in-memory database like SQLite is yet another option and would give you relational semantics should that be interesting to you.
To get started, I'd say use LocalFolder and persist your collection to a file, then when you rehydrate it, simple data binding should automatically handle the display. At some point, you may need to make a decision about how much to store. You want your application to be responsive for the user ('fast and fluid'), so to that end you may need to bring in data as it's requested versus all at once (perhaps a version 2 feature!)

Windows application storage location

I am working on a windows app. The user has to register first to use this application. So in order to store user information, I am using MS-Access as a database. There is not much information to be stored as this application will be on individuals machine. There are few settings and some user information to be stored.
What I am feeling is that with the use of MS-Access, my application will be dependent on other application as MS-Access. It is not necessary to have the MS-office on the end user's machine.
So can you suggest me the best way to store the data safely without any dependence.
One thing I want to clear is that, the information will be of different types like it will consists of user information, some folder/files paths and some other information. I would like to keep these information separate from each other.
Thanks
Abhie
I think I found the solution.
Best practice to save application settings in a Windows Forms Application
I hope this will help others facing same problem.
Stackoverflow Team You are doing fabulous job. One suggestion; can you put some chat option for developers to discuss their problems. I think this would make it more easy to find answers to complex problems...:)
Regards
you need to include Access Database Engine drivers in the client PC, in order to connect it .
MS Access Database Engine
If you're using .NET, the best bet for getting the recommended folder locations for application data (e.g. your mdb file) is probably best retrieved using Environment.GetFolderPath
See:
http://msdn.microsoft.com/en-us/library/system.environment.getfolderpath.aspx
You're likely interested in ApplicationData or LocalApplicationData for user specific data or CommonApplicationData for data shared by all users as your storage location (and then the proper company / product subdirectories appended to it).

Excel Add In (C#) - How to deal with user settings?

What is the best way to deal with User specific settings with an Application Level Excel 2010 Add In?
In my scenario, a user loads Excel with an Add In installed, this adds a new Ribbon option which allows a Winform to load. The Winform collects a single piece of data and then must attempt to persist that for the current user.
Does Excel provide a mechanism for this? Is the approach similar to vanilla Winforms (i.e. maybe IsolatedStorage)?
Many thanks,
Andy
Use the registry - that's what Excel does for writing various bits of information while it is running. The user's hive of the registry (HKEY_CURRENT_USER) is always accessible, so there are no permissions issues, and it is fast and unintrusive.
.NET has easy access to the registry through the Registry class : http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx.

Alternate (user-scoped) settings in a C# desktop application

1) I use Visual Studio 2008 (C#)
2) I want my desktop application to "remember" certain settings (preferences) for every user individually.
3) The application would use its own database of users (logins + passwords), so they have nothing to do with Windows accounts.
How can I accomplish that? Trying to find an answer
4) I've found the "Using Alternate Sets of Settings" subject on MSDN => http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx - but
5) it suggests that even these alternative settings need to be added in design time. That's a bit of a problem, because:
6) I don't know in advance, how many users would be in the database - and I want the "main user" (admin) to have an option of adding more accounts any time he wants.
So
7) how do I accomplish that?
So far I thought about:
8) using isolated storage files? (but they, too, are user-scoped in the sense of referring to Windows accounts)
9) deriving my own class from ApplicationSettingsBase class and supplying it with a SaveAs() method (which it lacks by default)?
Thanks for any answers / suggestions.
If my problem is not quite clear, I'm happy to clarify
If you have a database that stores users and passwords, why not store the application settings there as well? I'm assuming you're using SQL Server (Express or commercial)
All "Settings" are in .NET are key, value pairs, and I don't see why you couldn't accomplish this exact same functionality with a name value pair in the database.
I've found that the "Settings" and Configuration management tools are confusing and tricky to use, so if you have a database with users in it already, you might as well leverage your existing infrastructure.
You could use a SQLite database to hold all the data. (See System.Data.SQLite)
You should think about using the ASP.NET Membership provider. It allows for per-user personalization settings as well as 'all user' settings.
It was built for web sites, but you can configure it for use in a desktop application pretty easily. Also, there is a whole API that is already written for it.

Categories