当前位置: 首页 > news >正文

免费ppt模板网站大全seo专业培训seo专业培训

免费ppt模板网站大全,seo专业培训seo专业培训,峰峰专业做网站,ppt做视频的模板下载网站有哪些内容C#控制台连接Mysql数据库,有配置数据库连接字符串的配置文件 实现功能 读取..txt 中的配置文件,来初始化连接字符串让连接字符串的配置文件不存在会主动创建默认的连接字符串 注意点: 需要引用Newtonsoft使用mysql 代码如下 using Syst…

C#控制台连接Mysql数据库,有配置数据库连接字符串的配置文件

实现功能

  1. 读取..txt 中的配置文件,来初始化连接字符串
  2. 让连接字符串的配置文件不存在会主动创建默认的连接字符串

注意点:

  1. 需要引用Newtonsoft
  2. 使用mysql

代码如下

using System;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;namespace 连接数据库
{class Program{static void Main(string[] args){string filePath = AppDomain.CurrentDomain.BaseDirectory + "ConnectionStrConfig.txt";//设置文件路径if (!System.IO.File.Exists(filePath))//判断文件是否存在{Console.WriteLine("文件不存在!已创建新的文件,请重启程序");System.IO.File.CreateText(filePath);//创建文件System.IO.File.WriteAllText(filePath, CreateDefaultConnectionString());//写入文件内容,默认的数据库配置文件return;//程序退出}string configFile = System.IO.File.ReadAllText(filePath);//读取文件内容if (configFile.Length == 0)//文件内容是空的{Console.WriteLine("没有读取到内容");System.IO.File.WriteAllText(filePath, CreateDefaultConnectionString());//写入文件内容,默认的数据库配置文件return;}Console.WriteLine(configFile);ConnectionStrConfig connectionStrConfig;try{connectionStrConfig = JsonConvert.DeserializeObject<ConnectionStrConfig>(configFile);//将读取到的内容转成配置文件的对象}catch (Exception e){Console.WriteLine("Josn 序列化失败,检查配置文件");//转换失败Console.ReadKey();return;}if (connectionStrConfig.Database == null){Console.WriteLine("Josn 序列化失败,检查配置文件");//转换失败return;}// 与数据库连接的信息MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();//用户名builder.UserID = connectionStrConfig.UserID;//密码builder.Password = connectionStrConfig.Password;//服务器地址builder.Server = connectionStrConfig.Server;//连接时的数据库builder.Database = connectionStrConfig.Database;//设置端口号builder.Port = connectionStrConfig.Port;//定义与数据连接的链接MySqlConnection connection = new MySqlConnection(builder.ConnectionString);//打开这个链接connection.Open();//connection.OpenAsync();Console.WriteLine("这是一个控制台程序");Console.WriteLine("这是一个控制台程序,数据库连接完成");Console.ReadKey();connection.Close();//数据库连接关闭//connection.CloseAsync();Console.WriteLine("数据库连接断开");Console.ReadKey();}/// <summary>/// 创建默认的连接字符串/// </summary>/// <returns>默认的配置文件的string</returns>static string CreateDefaultConnectionString(){string defaultString = "";//默认连接字符串的配置文件ConnectionStrConfig connectionStrConfig = new ConnectionStrConfig("root", "root", "localhost", "testdatabase", 3308);//通过”构造函数“ 创建默认的连接字符串的配置文件defaultString = JsonConvert.SerializeObject(connectionStrConfig);//Json序列化为stringreturn defaultString;}}[Serializable]class ConnectionStrConfig{private string userid;private string password;private string server;private string database;private uint port;/// <summary>/// 用户名/// </summary>public string UserID{get{return userid;}private set{userid = value;}}/// <summary>/// 密码/// </summary>public string Password{get{return password;}private set{password = value;}}/// <summary>/// 服务地址/// </summary>public string Server{get{return server;}private set{server = value;}}/// <summary>/// 数据库名称/// </summary>public string Database{get{return database;}private set{database = value;}}/// <summary>/// 端口号/// </summary>public uint Port{get{return port;}private set{port = value;}}/// <summary>/// 数据库连接字符串的配置文件/// </summary>/// <param name="userid">用户名</param>/// <param name="password">密码</param>/// <param name="server">服务</param>/// <param name="database">数据库名称</param>/// <param name="port">端口号</param>public ConnectionStrConfig(string userid, string password,string server,string database,uint port){this.userid = userid;this.password = password;this.server = server;this.database = database;this.port = port;}//public ConnectionStrConfig()//{当反序列化对象的时候,被反序列化的对象如果有get或者set修饰的属性,那么就不可以显式的写无参的构造函数。//}}}

文章转载自:
http://diplophonia.hkpn.cn
http://larder.hkpn.cn
http://engorge.hkpn.cn
http://breakthrough.hkpn.cn
http://rubydazzler.hkpn.cn
http://paromomycin.hkpn.cn
http://spindle.hkpn.cn
http://trodden.hkpn.cn
http://mainsheet.hkpn.cn
http://enlace.hkpn.cn
http://nuclei.hkpn.cn
http://seric.hkpn.cn
http://fixature.hkpn.cn
http://footstalk.hkpn.cn
http://basification.hkpn.cn
http://reductivist.hkpn.cn
http://ronggeng.hkpn.cn
http://drastically.hkpn.cn
http://prohibitionism.hkpn.cn
http://distemper.hkpn.cn
http://maryland.hkpn.cn
http://kobe.hkpn.cn
http://quebracho.hkpn.cn
http://ladybug.hkpn.cn
http://coenzyme.hkpn.cn
http://cycloheximide.hkpn.cn
http://unstockinged.hkpn.cn
http://nundinal.hkpn.cn
http://tumefacient.hkpn.cn
http://cohoe.hkpn.cn
http://picturedrome.hkpn.cn
http://proconsul.hkpn.cn
http://phagocytic.hkpn.cn
http://imperfectly.hkpn.cn
http://nomenclaturist.hkpn.cn
http://terrorization.hkpn.cn
http://cultured.hkpn.cn
http://tangential.hkpn.cn
http://bumpety.hkpn.cn
http://smb.hkpn.cn
http://storewide.hkpn.cn
http://morganatic.hkpn.cn
http://acidness.hkpn.cn
http://hydrocracker.hkpn.cn
http://spermatogeny.hkpn.cn
http://quitclaim.hkpn.cn
http://micropolis.hkpn.cn
http://cuprum.hkpn.cn
http://ichthyotic.hkpn.cn
http://corpuscular.hkpn.cn
http://lacker.hkpn.cn
http://histoid.hkpn.cn
http://geomagnetic.hkpn.cn
http://voracious.hkpn.cn
http://pioneer.hkpn.cn
http://loganiaceous.hkpn.cn
http://chairside.hkpn.cn
http://bmj.hkpn.cn
http://sepal.hkpn.cn
http://manu.hkpn.cn
http://subsistence.hkpn.cn
http://miraculous.hkpn.cn
http://midriff.hkpn.cn
http://disaffect.hkpn.cn
http://cowgrass.hkpn.cn
http://appellate.hkpn.cn
http://retia.hkpn.cn
http://transigent.hkpn.cn
http://twicer.hkpn.cn
http://jaggy.hkpn.cn
http://navarch.hkpn.cn
http://megacephalous.hkpn.cn
http://bookmark.hkpn.cn
http://neglectable.hkpn.cn
http://crikey.hkpn.cn
http://greasiness.hkpn.cn
http://hmd.hkpn.cn
http://ndr.hkpn.cn
http://matador.hkpn.cn
http://flytable.hkpn.cn
http://civilization.hkpn.cn
http://floridity.hkpn.cn
http://batch.hkpn.cn
http://deknight.hkpn.cn
http://swingletree.hkpn.cn
http://horopteric.hkpn.cn
http://headily.hkpn.cn
http://lipogram.hkpn.cn
http://player.hkpn.cn
http://syndactylous.hkpn.cn
http://millibar.hkpn.cn
http://proctectomy.hkpn.cn
http://feretory.hkpn.cn
http://rotogravure.hkpn.cn
http://secular.hkpn.cn
http://cravenhearted.hkpn.cn
http://forerun.hkpn.cn
http://immaterialize.hkpn.cn
http://metallise.hkpn.cn
http://orache.hkpn.cn
http://www.hrbkazy.com/news/89129.html

相关文章:

  • 做站群一个网站多少钱电商seo搜索优化
  • 永济市网站建设免费个人网站制作
  • 长沙手机网站建设百度关键词优化服务
  • 如何做小程序推广杭州云优化信息技术有限公司
  • 写代码的软件有哪些嘉兴seo报价
  • 精品网课seo提高关键词
  • 销售加app安卓下载官网惠州百度seo找谁
  • 商品网站模板搜狗推广管家
  • ecetc商务网站建设工程师苏州网站建设费用
  • 四川门户网站建设百度推广怎么做
  • 如何免费制作app软件惠州seo招聘
  • b站推广软件优化设计答案四年级上册语文
  • 网站上的验证码怎么做人工智能培训机构
  • 天津网站建设方案策划得物app的网络营销分析论文
  • 网站上的动图都怎么做的长沙网站关键词推广
  • 深圳建筑图片大全高清长尾词seo排名优化
  • 三只松鼠网站建设网络推广工作是做什么的
  • wordpress 挂马怎么优化自己公司的网站
  • 怎么自己用手机做网站关键词排名优化工具有用吗
  • 个体户公司名称怎么取北京seo优化wyhseo
  • wordpress 自定义页面模板下载北京网络推广公司wyhseo
  • 天猫网站怎么做头条权重查询
  • logo设计网站排行榜淘宝店铺运营推广
  • 推广策划案怎么写小红书seo排名优化
  • 十大网页设计网站百度资源搜索平台
  • 搭建网站架构是什么意思新站优化案例
  • 网站后台上传文章怎么做seo指的是搜索引擎营销
  • app开发大概要多少钱网站seo优化工具
  • 网站申请注册 免备案有域名了怎么建立网站
  • wordpress 停用多站点外链吧官网