首页
友链
壁纸
留言
今日热榜
更多
关于
时光
推荐
精品流量卡
Search
1
都二十多年了,你的梦为什么还没碎!
57,088 阅读
2
2022年5个好用的 BT/ 磁力链接下载工具推荐 |Windows 、安卓系统
37,361 阅读
3
nps内网穿透实现外网访问树莓派
32,425 阅读
4
实践利用宝塔建emlog个人博客-超详细【原创】
26,132 阅读
5
Typecho-Joe-Theme主题帮助文档
24,619 阅读
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
登录
Search
标签搜索
PHP
HTML
API
Javascript
源码
JS
Vue
Github
CloudFlare
接口
函数
SQL
ASP.NET
MVC
EF
T4模板
后台管理
CDN
微信小程序
MAC
韩小韩
累计撰写
261
篇文章
累计收到
1,305
条评论
首页
栏目
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
页面
友链
壁纸
留言
今日热榜
关于
时光
推荐
精品流量卡
搜索到
2
篇与
数据库
的结果
2021-07-16
Node.js连接远程mongodb并利用mongorestore远程恢复数据库
{message type="info" content="之前在mongodb搞了个免费的512MB的mongodb数据库,刚好今天要搭建一个nodejs项目需要的数据库是mongodb,项目里的数据库连接的是本地localhost,因为是第一次接触nodejs + mongodb,以为改个IP地址就可以了,没想到折腾了好久都没搞懂。然后Search了好多教程大多都是本地连接,最终还是找到了,连接好以后需要用mongorestore恢复数据,又遇到了一个坑,运行mongorestore命令需要安装mongo-tools工具才可以,然后又安装了mongo-tools,最终完美连接并导入。"/}Node.js连接远程mongodb代码const mongoose = require('mongoose'); const db = mongoose.connect("mongodb+srv://数据库用户名:数据库密码@IP地址:端口/数据库名", { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }, function (error) { if (error) { console.log("连接远程mongo数据库失败:" + error.message) } else { console.log("连接远程mongo数据库成功") } }); module.exports = db;mongorestore恢复远程mongodb代码var process = require('child_process'); process.exec('mongorestore --uri="mongodb+srv://数据库用户名:数据库密码@IP地址:端口/数据库名" 需要恢复的数据文件目录', function (error, stdout, stderr) { if (error) { console.log("执行重置数据库失败, 异常信息:" + error.message) } else { console.log("执行数据库重置成功!") } })Node.js连接本地mongodb代码const mongoose = require('mongoose'); const db = mongoose.connect("mongodb://localhost:端口/数据库名", { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }, function (error) { if (error) { console.log("连接本地mongo数据库失败:" + error.message) } else { console.log("连接本地mongo数据库成功") } }); module.exports = db;mongorestore恢复本地mongodb代码var process = require('child_process'); process.exec('mongorestore -h 127.0.0.1:27017 -d 数据库名 需要恢复的数据文件目录 --drop', function (error, stdout, stderr) { if (error) { console.log("执行重置数据库失败, 异常信息:" + error.message) } else { console.log("执行数据库重置成功!") } })
2021年07月16日
225 阅读
0 评论
0 点赞
2019-03-07
C#三层架构实现WinForm连接Mysql显示数据库数据实例
首先创建数据库丨 学号 姓名 班级 QQ 微信 丨5列三层架构,即包含 BLL,DAL,Model,DBHelper,Winform必须 Mysql 包using MySql.Data.MySqlClient;请依照下列文件规范命名首先配置WinForm下 App.config 文件(Mysql数据库连接为例)<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name ="NiceHanMySql" connectionString="server=数据库地址;port=端口号;user=数据库用户名;password=密码; database=数据库名;"/> </connectionStrings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> </configuration>BLL 下 NiceBLL.cs文件代码using DAL; using Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BLL { public class NiceBLL { NiceDAL tableDal = new NiceDAL(); public List<NiceModel> GetTableList() { return tableDal.GetTablelist(); } public String NiceFormText() { return "NiceHan Mysql TextDate"; } public String SystemonLock() { return "NiceHanWinForm"; } } }DAL 下 NiceDAL.cs文件代码using Models; using SqlDbHelper; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; namespace DAL { public class NiceDAL { public List<NiceModel> GetTablelist() { string sqlStr = "select * from PZ "; DataTable sTable = NiceDB.GetDataTable(sqlStr, null); List<NiceModel> tableList = new List<NiceModel>(); foreach (DataRow dr in sTable.Rows) { NiceModel tb = new NiceModel(); tb.学号 = (dr["Num"].ToString()); tb.姓名 = (dr["Name"].ToString()); tb.班级 = (dr["Class"].ToString()); tb.QQ = (dr["QQ"].ToString()); tb.微信 = (dr["Wx"].ToString()); tableList.Add(tb); } return tableList; } } }Model 下 NiceModel.cs文件代码using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Models { public class NiceModel { public string 姓名 { set; get; } public string 学号 { set; get; } public string 班级 { set; get; } public string QQ { set; get; } public string 微信 { set; get; } } }DBhelper 下 NiceDB.cs文件代码using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Data; using MySql.Data.MySqlClient; namespace SqlDbHelper { public static class NiceDB { private static readonly string connStr = ConfigurationManager.ConnectionStrings["NiceHanMySql"].ConnectionString; public static int ExecuteNoneQuery(string sqlStr, params System.Data.SqlClient.SqlParameter[] pms) { using (MySqlConnection conn = new MySqlConnection(connStr)) { using (MySqlCommand cmd = new MySqlCommand(sqlStr, conn)) { if (pms != null) { cmd.Parameters.AddRange(pms); } conn.Open(); return cmd.ExecuteNonQuery(); } } } public static object ExecuteScalar(string sqlStr, params MySqlParameter[] pms) { using (MySqlConnection conn = new MySqlConnection(connStr)) { using (MySqlCommand cmd = new MySqlCommand(sqlStr, conn)) { if (pms != null) { cmd.Parameters.AddRange(pms); } conn.Open(); return cmd.ExecuteScalar(); } } } public static MySqlDataReader ExecuteReader(string sqlStr, params MySqlParameter[] pms) { using (MySqlConnection conn = new MySqlConnection(connStr)) { using (MySqlCommand cmd = new MySqlCommand(sqlStr, conn)) { if (pms != null) { cmd.Parameters.AddRange(pms); } try { conn.Open(); return cmd.ExecuteReader(); } catch { conn.Close(); conn.Dispose(); throw; } } } } public static DataTable GetDataTable(string sqlStr, params MySqlParameter[] pms) { using (MySqlDataAdapter adapter = new MySqlDataAdapter(sqlStr, connStr)) { DataTable dt = new DataTable(); if (pms != null) { adapter.SelectCommand.Parameters.AddRange(pms); } adapter.Fill(dt); return dt; } } } }Winform 下 NiceHanForm.cs文件代码using BLL; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace NiceHanForm { public partial class NiceHanForm : Form { public NiceHanForm() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { NiceBLL tb = new NiceBLL(); this.Text = tb.SystemonLock(); this.WinForm.Text = tb.NiceFormText(); this.dataGridView1.DataSource = tb.GetTableList(); } } }恭喜你完成 运行调试即可
2019年03月07日
3,147 阅读
0 评论
0 点赞