-
-
Notifications
You must be signed in to change notification settings - Fork 41
数据库连接配置
Argo edited this page Jan 7, 2019
·
1 revision
"ConnectionStrings": {
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
},
"MongoDB": "BootstrapAdmin",
"DB": [
{
"Enabled": false
},
{
"Enabled": false,
"ProviderName": "Sqlite",
"ConnectionStrings": {
"ba": "Data Source=BootstrapAdmin.db;"
}
},
{
"Enabled": false,
"ProviderName": "MySql",
"ConnectionStrings": {
"ba": "Server=localhost;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"
}
},
{
"Enabled": false,
"ProviderName": "Npgsql",
"ConnectionStrings": {
"ba": "Server=localhost;Database=BootstrapAdmin;User ID=argozhang;Password=argo@163.com;"
}
},
{
"Enabled": true,
"Widget": "Bootstrap.DataAccess.MongoDB",
"ConnectionStrings": {
"ba": "mongodb://10.211.55.2:27017"
}
}
]
本项目使用的是PetaPoco Mini ORM框架为基础,所以数据库驱动未显示引用到项目中,切换数据库时需要自行根据自己设置的数据库加载自己的数据库驱动组件
默认数据库连接字符串
数据库配置项
Enabled: 是否生效
ProviderName: 数据库类型,未配置默认使用Microsoft SQLServer
Widget: 数据库实体类程序集,此程序集负责具体数据库CRUD操作,未指定时默认使用Bootstrap.DataAccess程序集
ConnectionStrings: 数据库连接字符串,未配置使用上面的默认数据库连接字符串
以上面代码为例,由于前面的配置项中的Enabled均为false,最后一个MongoDB配置项为true,则系统采用此配置,使用MongoDB作为系统数据库,根据其配置项内的ConnectionStrings下的数据库连接字符串,开发环境中需要自己额外显示增加MongoDB数据库驱动组件([Nuget]MongoDB.Driver)的引用以及增加对Bootstrap.DataAccess.MongoDB工程的引用,发布生产环境中需要自己拷贝相关依赖文件到bin目录下
MongoDB DatabaseName,配置文件中设置为设置MongoDB中BootstrapAdmin数据库,Collection请自行导入解决方案MongoDB文件夹内的初始化文件,数据库中集合名称为文件名移除BootstrapAdmin前缀后面的单词,如Dicts/Groups等
- 设置配置文件中 DB 小节下 MongoDB 配置项 Enabled 为 true 其余的配置项为 false 值
- 引用 MongoDB 数据库驱动 MongoDB.Driver
- 引用 Bootstrap.DataAccess.MongoDB工程
- 导入数据库Collection