I wrote a C # application that works with MS SQL database. If I transfer the application to another computer and try to run it, it doesn’t work. there is no database with which I work. How to make that when you run the program on different computers, the database is installed automatically?

  • You can use the MS SQL connection to the file, put the database file in the project and distribute it with your application. However, this option will still require the availability of SQL Server on the client’s machine, even the Express version, well, of course, if the database is quite small and does not contain complex connections and logic, it is better to use something easier. - rdorn
  • one
    Possible duplicate question: C # MSSQL What is needed to run? - MSDN.WhiteKnight

2 answers 2

You are a little different from using SQL database. This database is installed on the server and your application connects not with the database itself, but with the server. And he already in turn and works with the database.

If you need data to be stored near the application, then use SQLITE

As for the example of using example 1, example 2

  • I can choose only from MS SQL and MySQl. Which one is better to work with? - Denis
  • It's not about how to work better, but why you need them. With databases such as MySQl, PostgreSQL, etc. This does not work. They are not dragged along with the application. They lie on the server (metal box) to these databases the server is connected (this program you wrote is not a metal box, but another one, just called the same) and the server is already working with the database and giving the data to your application. If you want the database to be next to the application, then you need to use SQLITE, it was written for this in principle. - Andrey Zimin
  • At home, just do really place a server on a laptop and store this database there? - Denis
  • If you're talking about MySQl, PostgreSQL, and others like them, yes of course. You can install any of them, write a server to work with it, and run it locally. And then, when the creation will be ready - to spread on a rented server and deploy there. (you can use the cloud - here it’s a matter of taste and tasks) Again, when using SQLITE, the approach is slightly different. This base is more for the maintenance of the application itself and the data of only this one application. For example, in it you can store some user data, post loaded (again from the server) news, etc. - Andrey Zimin
  • one
    I do not agree, SQLite is certainly fashionable and youth, especially for mobile platforms, but if we talk about the Win-platform, then SQL Express and LocalDb can digest much larger data in terms of volume and complexity, and at the same time they will work with a single file that comes with the application . In addition, in the latest versions of Win, LocalDb is usually already worth it, because used by internal services - rdorn

Denis, code first , read here, there is still a video on YouTube, there the person has described everything in detail. With this approach, the application itself creates the database if the necessary SQL is installed on another machine