NeuCharFramework (NCF)
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF Overview

    • NCF - NeuCharFramework
    • About NCF
    • Environment Requirements
    • Frontend and Backend Separation Mode
    • Introduction to Xncf Modules
  • Prepare Development

    • Get NCF Template Source Code
    • Using Visual Studio to Run NCF
    • Running NCF Using CLI
    • Installation
    • Admin Login
    • Admin Backend
    • appsettings.json Configuration
    • Module Management
    • Accessing Documentation
  • Configuration

    • Entry File
    • Database Settings
    • appsettings.json Configuration
    • Docker
    • Dapr
    • Configure Multi-Tenant
    • Redis Cache
  • Modular Development

    • NCF Modular Development Concept
    • Composition of Xncf
    • Create the First Xncf Module
    • Xncf Module Sample Detailed Explanation
    • Implement Your Own Business Logic
    • Update Xncf Module
    • How to Call Between Modules
    • Publish Xncf Module to nuget.org
    • Update Base Library
    • Xncf Module Development
    • Embedding Static Resource Files into NCF
    • Publish Local Nuget Package
    • Advanced
  • Database

    • Database Settings
    • Multi-Database Support
    • Specify Database
    • Update database migration files for the Senparc.Service project (Migrations)
    • Multi-Database Principle
    • DatabasePlant
    • Tarmac Operation Database Migration and Update
  • Unit Testing

    • NCF Unit Test Introduction
    • Start Development
    • Advanced
    • Appendix
  • Q&A

    • NCF Terminology
    • NCF FAQ
  • Release

    • New Features
    • Upgrade Guide
    • Logs

Specify Database

NCF can quickly specify the database in a convenient way. After switching, rerun, and the database can be seamlessly migrated.

The following example uses MySQL to demonstrate how to quickly switch databases. The operation method for other databases is the same, just change MySql to the corresponding database name in the process. Of course, you may also need to set the correct database connection string.

How to Quickly Switch to MySQL

Step1. Modify SenparcConfig.config

First, find the SenparcConfig.config file in the Senparc.Web\App_Data\DataBase directory and modify the MySQL node as follows:

	<SenparcConfig>
		<Id>4</Id>
		<Name>Local-MySql</Name>
		<!--Local Demo default database (can modify DatabaseName configuration in appsettings.json)-->
		<ConnectionStringFull>
			<![CDATA[Server=localhost;Database=NCF;Uid=root;Pwd=root;]]></ConnectionStringFull>
		<ApplicationPath><![CDATA[/]]></ApplicationPath>
	</SenparcConfig>

Step2. Modify Senparc.Web.csproj File

Add the following Senparc.Ncf.Database.MySql reference:

<PackageReference Include="Senparc.Ncf.Database.MySql" Version="0.11.3-beta7" />

Step3. Modify the Startup File's Database Options

Method 1: Modify appsettings.json File (Recommended)

This method does not modify any files that need to be compiled, just modify the configuration file appsetting.json.

Find the Senparc.Web\appsettings.json file and modify the SenparcCoreSetting node's DatabaseName from the default Sqlite to MySql:

  "SenparcCoreSetting": {
	//...

    "DatabaseName": "Local", // Corresponds to: AppData/DataBase/SenparcConfig.config, the Name prefix of the database connection to be used in the <SenparcConfig> node
    "DatabaseType": "MySql"

	//...
  },

Method 2: Modify the Code:

Find the \NCF\src\Senparc.Web\Program.cs file code:

app.UseNcf<BySettingDatabaseConfiguration>();

Change BySettingDatabaseConfiguration to MySqlDatabaseConfiguration:

app.UseNcf<MySqlDatabaseConfiguration>();
【Note】: Due to the support of the EFCore base library, the MySQL engine must be InnoDB. If it is set to Mylsam, an error will occur at runtime, and the error message is as follows

Exception Handling: Error when starting after modifying MySQL configuration

How to Quickly Switch to SqlServer

Same as switching to MySQL.

After switching, running will display, the same below.

How to Quickly Switch to Sqlite

Same as switching to MySQL.

How to Quickly Switch to Oracle

Same as switching to MySQL.

How to Quickly Switch to Dameng Database (Dm)

Same as switching to MySQL.

Edit this page on GitHub
Last Updated:
Contributors: Jeffrey Su
Prev
Multi-Database Support
Next
Update database migration files for the Senparc.Service project (Migrations)