Update database from external JSON with scheduled task on Windows server - asp.net-mvc-5

I have an ASP.NET MVC 5 project with database and external JSON file that is updated once a day, by third-party website.
What I'm trying to do is to update my DB once a day accordingly with the JSON (the precision is not the issue here).
Currently I'm using a button that call to Action that parsing the JSON and update the database, and I want to do it automatically.
As far as I understood, running the scheduled task from the MVC application is bad practice and risky, and running external dedicated service is preferred.
If I understood it correctly, I can make a console application that will parse the JSON and update the DB automatically, but I'm not sure if this console application can run on the windows server, and if so, how to do it (and I'm also not sure that this is really good idea).
So, I would be very happy if you can advise me here.
Thanks.

Finally the solution was to build a console application that parse JSON and updating the database.
Then, I used the built-in task scheduler in my hosting control panel to run the application (in my case the control panel is plesk)

Related

Publishing ASP.NET MvC to Azure with SQLite - data fetching fails

Just created a simple ASP.NET MvC project, to list blood pressure measurements. I opted to use SQLite as a database as it is (supposedly) embedded into the project, therefore eliminating the need for an external database. Which is expensive, and the reason why I chose to go with SQLite. That way I would only need to host the web app, which is free, if I chose the free tier, F1.
Publishing through VS2022 is successful, and the app shows correctly, except it shows none of the measurements. Which renders the app ((no) pun intended) useless, at least as a cloud app. I have done some research, and changed the publishingsettings a couple of times, but this is how they look right now.
Configuration: Release
Target Framework: net6.0
Deployment Mode: Self-contained
Target Runtime: win-x86
File Publish Options: None of the options chosen
Databases: Default Connection - Use this connection string at runtime:
=> Data source=bloodpressuremeasurements.db
Entity Framework Migrations: BloodPressureContext (name of the DbContext)
- Apply this migration on publish: NOT chosen, since it gave me an exception and publish failed
Site Extension Options: Install ASP.NET Core Logging Integration Site Extension
- NOT chosen
I also tried changing the option for the db file to Copy To Output Directory: Copy always.
That didn't change a thing. What am I missing?
The website works now as intended, with all the data shown. It looks like the problem stems from scaffolding read and write methods, which made Visual Studio 2022 pull in EntityFrameworkCore.SqlServer. Which is not what I wanted, since I'm using SQLite.
That in turn created some service dependencies under Connected Services, one of them being SQL Server something. It also appeared under the Publish menu, and seems to have caused the compilator to view the connection string as an SQL Server database connection.
I created a new app, and copied the code from the first one. I was careful not to scaffold, as I only need a Get method, to show all measurements. I need none of the other methods in CRUD, neither Post, Delete, nor Update. I will add new measurements by running the app again locally, and read the measurements from a CSV file (did that in the beginning). Then I will publish the app anew, with the updated SQLite database.

How do you tell entity framework to create / deploy a database in Azure?

I'm using Entity Framework with a code first model; I've got my InitialCreate migration setup and working locally, I can run code against my database context, and everything works.
But when I deploy my project to Azure, I just get a connection string error ("Format of the initialization string does not conform to specification starting at index 0.").
I can't seem to find where in the Publish dialog are the options to create the Azure database. -- Do I have to create the database separately and hook them up manually? -- If so, what exact process should I follow. Does the database need to have contents?
I thought Microsoft was making a big deal that this could all be done in a single deploy step, but that doesn't seem to be the case from my current experience.
When you publish your project in the publish dialog, there is an option for the code first migration in the Settings tab, it will automatically show your data context and it will give you the option to set the remote connection string, and this will add a section in web.config to specify the data context and the Migration class to run during the migration process.
It will also allow you to set if you want to run the code first Migration or not.
You can also take a backup from the dev and clear the data then upload it to Azure SQL DB, this way the code first data context will check at first connection and it will find the code an database the same

Broadleaf Running core and Admin

I am using Broadleaf for one of my project. I want to use only the admin and core module. But when I run the project I have this error " Table 'broadleaf.blc_system_property' doesn't exist". Is it possible to run the demosite without the site module. I mean just core and admin.
Thank
By default, the site application is started with this set in the 'site' application, in site/src/main/resources/runtime-properties/development.properties:
blPU.hibernate.hbm2ddl.auto=create-drop
With this setting, the following happens when you start up the site application:
Application start
All database tables are dropped
All database tables are created
The load SQL in core/src/main/resources/sql is executed
Application finishes starting up
--- Application runs for however long it runs; do cart operations, register customers, etc
Shut down application
All database tables are dropped
Application is done shutting down
In the admin application, this is set in admin/src/main/resources/runtime-properties/development.properties:
blPU.hibernate.hbm2ddl.auto=none
With that setting, this is what happens:
Application Start
Nothing happens with the database
Application finishes starting up
--- Run for however long
Shut down application
Application is done shutting down
Basically, to fix your issue you want to change it such that when you start up the admin application it also creates tables and runs the import sql. I recommend changing this to create. So in admin/src/main/resources/runtime-properties/development.properties change it to this instead:
blPU.hibernate.hbm2ddl.auto=create
With that setting, this is how the application will behave:
Application start
All database tables are dropped
All database tables are created
The load SQL in core/src/main/resources/sql is executed
Application finishes starting up
--- Application runs for however long it runs; do cart operations, register customers, etc
Shut down application
Application is done shutting down
check your database, seems like this table is not there. On Unix like systems the table names are case sensitive so if your table was created in upper case, that would be the reason why broadleaf can't find it.
Yes and it is possible to run the admin without the site. To do that, just deploy the admin.war. Core is a separate maven module that is used by both the admin and site and is packaged as a jar in the war files.

Access 2013 web app - restoring previous app snapshot package without reverting data (structured staging environment)

I have a reasonably complex Access 2013 web app which is now in production on hosted O365 Sharepoint. I would like to take a backup (package snapshot) into a test environment, and then migrate this to production once development is complete (I certainly don't want to do development on the production system!). The problem is that the snapshot also backs up all data so uploading the new package over the top of the existing package in the sharepoint app repository reverts the data to the time of snapshot as well. Alternatively, rolling back to the original snapshot if there are issues would lose all data after the new package was applied.
I can easily get a second version of the app going by saving as a new application etc but this creates a new product ID etc in the app store. We also use a Access 2013 desktop accdb frontend to hook directly into the Azure SQL database to do all the stuff that the web app can't provide (formatted reports etc) so I cant just create a new app every time without dealing with all of the credential and database renaming issues.
So my question is, does anybody know how to safely operate a test environment for Access 2013 web app development? One needs to be able to apply an updated version, or rollback to the old one if there are problems without rolling back the data. With the desktop client I can just save a new copy of the accdb file every time obviously. I dont mind creating a new instance or link to the app on sharepoint each time, however this obviously generates a totally new database (server name, db location, login id's etc) as well. You would hope there is a way to upload and replace your app without touching the data, else how else can you develop without working directly in production?
Any answers would be really appreciated.
Thanks.

Modifying Cruise Control.NET

We are investigating using CruiseControl.NET as both a Continues Integration build provider, as well as automating the first part of our deployment process.
Has anyone modified CruiseControl.NET's dashboard to add custom login and user roles (IE, Separate out access to forcing a build to only certain individuals on a per project basis?
The dashboard is a .NET App, but I believe it uses the nVelocity view engine instead of web forms, which I don't have experience with.
Can you mix nVelocity and Webforms,or do I need to spend a day learning something new =)
#Keith:
We are leveraging CC.NET to both run a CI build, as well as being able to use the Force Build feature to do a Build + Deploy. That is why we want hands off the dashboard.
I found this morning that I was able to place CCNET in a virtual directory within another web app, This allowed me to setup Forms Authentication, and let the root app manage that. Problem solved.
Why do you need to? Do you really need to limit users in the way with an integration server. I think that's why CC.Net doesn't have that sort of support built in.
You can always see who forced a build, and control it that way.
I find that continuous integration works best with regular builds and regular unit test runs (our rather large C# app + test run takes 25 mins and checks hourly), so for me forcing a build is rarely an issue.
If you want some users to have some kind of report-only access you could limit them so that they can't access the CC.Net web application at all.
All the results (MSBuild, NCover, NUnit, FxCop, etc) are in XML, so you can build relativity simple report pages out of XSLT.

Resources