How to store data in .net windows application

What would be the best way to store data in a Windows forms application?

I started a project using SQL with a local .mdf file, but soon realized that I was creating the installer and installing it on another system. I get an error when SQL Server is not found because SQL is not installed on this server.

The target system in which this application will be installed will not install SQL.

So my question is: what is the norm? How is data usually stored and accessible in Windows form applications? Is this really a .mdf SQL database or some type of sqlite DB?

If I can use an SQL database (mdf file) of some kind, without having to install an SQL server on every client computer. How can I do it?

Thanks!

+4
source share
9 answers

Now there is SQL Server Compact Edition. This is compiled directly into your application. End users will not need any other version of SQL Sever to use your application. See http://www.microsoft.com/sqlserver/en/us/editions/compact.aspx

+7
source

Then you should use the built-in database. SQL Server Compact Edition is an embedded database. This Wikipedia link points to other embedded databases:

http://en.wikipedia.org/wiki/Embedded_database

Please note that not all are free.

+3
source

The answer to this question is nontrivial. I assume that you are storing the actual content, not just the settings or window positions. The first option is to use one of the built-in serializers to read / write XML or JSON. Or perhaps use one of ServiceStack.

If you cannot easily store all content in memory, we may consider using a database. The only time I have ever used a heavyweight database such as MS SQL Server or Oracle would be where you have an enterprise application with full-time employees who manage the databases.

For simple file storage for each application, you can use MS SQL Embedded or Express editions, but do not. It is slow. He has stupid restrictions. You can look at the connection string parameters on the Internet to point to the local mdf file if you really want to go down this road.

Rather, you should probably use the Sqlite.NET shell (it is now managed and provided by Sqlite.org). If you want to use shallow ORM, I also recommend doing this. You can watch ServiceStack or many other options in this arena. (Just do a web search for lite .net orm).

+3
source

If you really want to use SQL, you can use SQL Server Compact edition. It will create a db file, and you can use it as a regular datbase (with some exceptions)

http://www.microsoft.com/sqlserver/en/us/editions/compact.aspx

+2
source

For the built-in RDBMS, you will not go wrong in SQLite as the "Widely Deployed SQL Database" on the planet. This is a file RDBMS that just works, the database is autonomous and not even needed, because you can transparently create it on the fly.

My ServiceStack OrmLite supports 32-bit and 64-bit SQLite providers, which makes it trivial to work with its first-class support for POCOs: Auto table creation and transparent support for text blocks containing no schemas for complex property types.

It is loaded from NuGet in 2 options:

The following is an example of a simple web service :

using (IDbConnection db = "~/App_Data/db.sqlite".OpenDbConnection()) using (IDbCommand dbCmd = db.CreateCommand()) { dbCmd.DropTable<Author>(); dbCmd.CreateTable<Author>(); var authors = new List<Author> { new Author { Name = "Demis Bellot" ... }, new Author { Name = "Angel Colmenares" ... }, }; dbCmd.InsertAll(authors); dbCmd.Select<Author>(q => q.Birthday >= new DateTime(agesAgo, 1, 1) && q.Birthday <= new DateTime(agesAgo, 12, 31)); dbCmd.Select<Author>(q => Sql.In(q.City, "London", "Madrid", "Berlin")); dbCmd.Select<Author>(q => q.Name.StartsWith("A")); dbCmd.Select<Author>(q => q.Name.EndsWith("garzon")); dbCmd.Select<Author>(q => q.Name.ToUpper().EndsWith("GARZON")); dbCmd.Select<Author>(q => q.Name.Contains("Benedict")); dbCmd.Select<Author>(q => q.Eaqings <= 50); dbCmd.Select<Author>(q => q.Rate == 10 && q.City == "Mexico"); } 

And a screenshot .

+2
source

You can also use SQLite , a free database library that stores data in text files. There is a .NET library for interacting with SQLite data files.

Another nice bonus is SQLite support from several languages. SQLite was originally written for C / C ++, but now Python has a built-in SQLite module. SQLite is also widely used in Java, Ruby, and many others.

+1
source

It mainly depends on what data you want to save.

Application parameters and user configurations are a type of data stored in programs. Such data is usually stored in xml configuration files or in the Windows registry.

Real business data is much more complex and needs a more advanced data warehouse, such as databases. To do this, you have several options:

  • Full-featured database engine such as MS SQL Server (Express), MySql or PostgreSQL. All of these DBMSs require a server application that must be installed on the computer in order for the data to be saved.

  • Built-in database engine such as SQL Server Compact Edition, or SQLite . I personally prefer SQLite. It has a .NET implementation ( System.Data.SQLite ). These DBMSs do not require any installation, and they can be easily deployed with any application. Although they have some limitations, they are enough for simple applications that do not have or have little simultaneous access to data.
    The most important limitations of SQLite (what I know) is that it does not have row-level locking (only table locking), and it does not have an external join right (only a left outer join). By default, external constraints are disabled by default. There, the first limitation somehow reduces the sensitivity of the application to simultaneous access to data (insert and updates). Others can be easily overcome.

+1
source

You can insert the ms sql express installation into the installation of your application or save the data if they are not large in the xml or ms office acess db format.

0
source

Among other options already mentioned, you can consider using the MS Access database (JET engine). Accessible from the box, and you can easily manage data using Access.

0
source

Source: https://habr.com/ru/post/1401667/


All Articles