mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 05:34:51 +00:00
Problem with placement of large files and database file. #862
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @IgorVolod on GitHub (Mar 30, 2023).
Originally assigned to: @GregorBiswanger on GitHub.
Hello!.
I just started using the electron net, its work satisfies me quite well. I have a question that probably has obvious answers, but I didn't find any.
I stumbled over migrating a database from a server to a local machine. I dug on the stack and the git, I could not find clear recommendations.
After installing the application, the first time you run EF, it creates a new database. If you run the installation of the application again, then during the installation process the entire working directory is cleared and the database is deleted. I need to keep her.
Question: Any recommendations on how to deploy a database? so that it remains even after deleting the application. I couldn't find.
From electron's manual: app.getPath(appData)
and a word of caution: it is not recommended to write large files here, as some environments may back up this directory to cloud storage.
Lead me on the right path!
The second question is about storing video files. Same problem. The video stream is being written in the process, now the video files are saved in wwwroot\Videostream
and are also deleted when the application is reinstalled. They're big.
If you can help, thank you very much! So that I do not invent a bicycle that can suddenly break down. I understand that the question is not about the work of electron net, so if you delete it, I won't be offended.)
@GregorBiswanger commented on GitHub (Mar 30, 2023):
It's great to hear that you're enjoying Electron.NET! I'll do my best to help you with your questions.
It sounds like you're looking for a local database? These are often only file-based and you can create these local database files externally from your application so that the data is available again after deletion. SQLite is suitable for this. It can be used with C# and also with the Entity Framework.
Deploying a database (SQLite solution):
To use SQLite in your Electron.NET project, first, add the
Microsoft.EntityFrameworkCore.SqliteNuGet package:dotnet add package Microsoft.EntityFrameworkCore.SqliteUpdate your DbContext to use SQLite, and make sure the connection string includes the path to the SQLite database file stored in the
userDatafolder:In this example, the connection string is built at runtime by getting the path to the userData folder and combining it with the name of the SQLite database file. The resulting connection string is used to configure the DbContext for SQLite.
Now, your application should use an SQLite database in the userData folder. This database file will persist even when the application is deleted and can continue to be used upon reinstallation.
Storing video files:
For video files, you can also use the
userDatafolder or another dedicated folder outside of the application's working directory to store them. You could create a subdirectory within the userData folder specifically for video files. Here's an example of how to do this in your Electron.NET application:I hope this guide helps you. If you have any more questions, please don't hesitate to ask.
@IgorVolod commented on GitHub (Mar 31, 2023):
Good afternoon
Thanks a lot for the solution!
In 15 minutes, I replaced the target DBMS and the corresponding provider, msSQL was replaced with SQLit.
The build is complete and the project is running, the database is now located in the UserData directory. This is cool!
I'm using the MVC concept, and I'm loading data onto the page via ajax post() requests in json format. An error occurred when loading multiple points to plot multiple curves on a graph. The source of the error is that not all arrays are returned in the responses of the controller methods, and this happens not constantly, but periodically (graphs can be built or built, but not all curves).
Weird error..., I don't think it's related to the switch to SQLite, now I'm trying to isolate the reason for this behavior. As there is an understanding, I will definitely let you know where this problem occurs.
@IgorVolod commented on GitHub (Mar 31, 2023):
The problem is solved, the problem was in my JS, when calling synchronous and asynchronous functions at the same time, the fall of the synchronous one led to the cancellation of the asynchronous function call. Making all js functions asynchronous solved the problem.
I was debugging, and some shortcomings were discovered (maybe only me):
Before starting the build, I have to run the command: chcp 65001

It switches the character encoding in the Windows console to UTF-8 (code page 65001)
Otherwise:
I couldn't run the app in debug mode unless I run the "Rebuild app" command before launching. Otherwise, the message in the application window:
Error.
An error occurred while processing your request.
VS debugging breaks at the line:
All these problems do not cause me any particular inconvenience, I report them for the sake of information.