资源简介
具体内容查看:
代码片段和文件信息
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Emergency.DBClient
{
public class MySQLconnection
{
///
/// MySqlConnection连接对象
///
private MySqlConnection connection;
///
/// 服务器地址
///
private string server;
///
/// 数据库实例名称
///
private string database;
///
/// 用户名
///
private string uid;
///
/// 密码
///
private string password;
///
/// 端口号
///
private string port;
public MySqlConnection getInstance() {
return connection;
}
///
/// 初始化mysql连接
///
/// 服务器地址
/// se“>数据库实例
/// 用户名称
/// 密码
public void Initialize(string server string database string uid string password)
{
this.server = server;
this.uid = uid;
this.password = password;
this.database = database;
//string connectionString = “Data Source=“ + server + “;“ + “port=“ + port + “;“ + “Database=“ + database + “;“ + “User Id=“ + uid + “;“ + “Password=“ + password + “;“ + “CharSet = utf8“; ;
string connectionString = “server=“ + server + “;user id=“ + uid + “;password=“ + password + “;database=“ + database;
connection = new MySqlConnection(connectionString);
}
///
/// 打开数据库连接
///
/// 是否成功
public bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
//When handling errors you can your application‘s response based on the error number.
//The two most common error numbers when connecting are as follows:
//0: Cannot connect to server.
//1045: Invalid user name and/or password.
switch (ex.Number)
{
case 0:
Console.Write(“Cannot connect to server. Contact administrator“);
break;
case 1045:
Console.Write(“Invalid username/password please try again“);
break;
}
return false;
}
}
- 上一篇:C#测试与欧姆龙FINS TCP通信
- 下一篇:加密算法,采用js加密,c#可以解密
相关资源
- 加密算法,采用js加密,c#可以解密
- C#测试与欧姆龙FINS TCP通信
- C#TreeView将左侧数据添加到右侧树视图
- c#基于TCP协议的Socket通信完整Demo已实
- C#画图程序
- C#可配置数据源的SPC代码
- C#实现的MODBUS主机模拟器
- C#实现的物流管理系统
- c#代码混淆器,混淆单个文件和整个目
- C# 多线程开发源码事例
- C#语言的各阶牛顿迭代法比较有源码
- 图片与视频播放器带加密功能- C#源码
- C# 员工信息管理系统 GUI
- 毕业设计所需外文翻译NET and C#原文
- C#员工管理信息系统
- C# winform文件目录复制 带进度条 类似
- C#做的随机分组小程序亦可用于抽签摇
- C/S模式的TCP点对点聊天程序C#源码
- C#实现对Oracle数据库的增删改查
- C# 网络编程之socket tcp 通讯demo样例
- C#Socket编程.rar
- C# 绘图 矩形 椭圆 直线 曲线 带控制点
- C#_winform_多个窗体之间相互传递数据操
- C#_winform_DataGridView_checkbox复选框_实现
- C#上的echarts的
- C#实时检测USB设备的插拔并响应各个事
- C#围棋程序
- C#数据表格控件的应用数据库插入删除
- asp.net留言簿实验报告
- c#控制Visio画图
评论
共有 条评论