在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、常用属性
using MySql.Data.MySqlClient; using System; using System.Data.Common; namespace ConsoleApp { class Program { static void Main(string[] args) { string str = string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", "localhost", 3306, "wisdompurchase", "root", "1234"); DbConnection conn = new MySqlConnection(str); //创建连接 //连接的数据库名称 Console.WriteLine(conn.Database); //wisdompurchase //建立连接最大尝试时间(秒) Console.WriteLine(conn.ConnectionTimeout); //15 //数据库连接字符串 Console.WriteLine(conn.ConnectionString); //"Server=localhost;Port=3306;Database=wisdompurchase;Uid=root;Pwd=1234"; //数据库实例的值 Console.WriteLine(conn.DataSource); // localhost conn.Open(); //要连接的SQLServer版本信息 Console.WriteLine(conn.ServerVersion); //5.7.17-log conn.Close(); //返回值为枚举类型,转到定义可以看说明 Console.WriteLine(conn.State); //Closed,已关闭 Console.ReadKey(); } } }
二、常用方法
using MySql.Data.MySqlClient; using System; using System.Data; using System.Data.Common; namespace ConsoleApp { class Program { static void Main(string[] args) { string str = string.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", "localhost", 3306, "wisdompurchase", "root", "1234"); DbConnection conn = new MySqlConnection(str); //创建连接 //连接的数据库名称 DbCommand cmd = conn.CreateCommand(); //创建DbCommand对象 conn.Open(); //打开连接 DataTable dt = conn.GetSchema(); //输出数据库的架构信息 foreach (DataRow dr in dt.Rows) { Console.WriteLine(dr[0]); } conn.Close(); //关闭连接 MySqlConnection.ClearPool((MySqlConnection)conn); //清空conn连接池 MySqlConnection.ClearAllPools(); //清空连接池 Console.ReadKey(); } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论