Home > front end >  Run a c# program with local database on another computer
Run a c# program with local database on another computer

Time:01-19

To keep things simple - I am developing a course project for my college assignment. I created an application in WinForms and C#. To store various data of this application, such as Registration Info, accounts, and various application functions-related data, I used Microsoft SQL Server Database. Now in the end, I realised, that I will not be able to send the project to my teacher, it will not run on his computer, because after some reading and research I found I might need an mdf file which I could not find, which I assume is because I created the tables in the SQL Server app, not through Visual Studio.

My connection string: con = new SqlConnection(@"Data Source=MyPC;Initial Catalog=SISDB;Integrated Security=True");

As you can see, connection string is hardcoded to my computer

My question is - what are the steps, or what I should do, so that this app would run just as well on my teacher computer with no issues with database?

CodePudding user response:

As far as I can see you have a few options:

Run the software on your computer

Either bring your computer to your teacher, or use your favorite remote desktop software. This should allow you to demonstrate that your program functions without needing to reinstall it.

Install the database on your teachers computer

This would potentially involve some instructions on how to install the database, as well as including the schemas and data. Or potentially create an installer or script that does all or part of the setup processes. This would probably require the most work from your teachers side.

Access the database remotely

Change the connection string to access your computer over the network. This will likely involve opening ports in the firewall, and this may be difficult there is any external firewall. This will also require your computer to be online. A problem with this is the difficulty of testing, and may result in cases where it works fine for you but not for your teacher.

Change your program

There is several types of embedded databases that can be run and deployed as part of your program. SqLite is probably the most popular, but there are many alternatives. In some cases it might be sufficient to just store data in a regular Json-file. This option would naturally involve rewriting part of your program.

In the end I would recommend talking to your teacher, explaining the situation and ask him/her what option would be easiest for both of you.

In the real world you would need to consider database deployment and upgrades as part of your initial design. You would often design a (web)service on top of the database to give your client a higher level API than SQL.

CodePudding user response:

You must use the version of Express SQL Server. You can put the packages related to your program along with the Express version in the installation file. Then, after installing on another system, the program will run without issue.

  •  Tags:  
  • Related