mysql-connector-net-8.0.11.msi 可以从这里下载:mysql-connector-net-8.0.11
 
如果使用ado.net链接mysql数据库则只需要引用  MySql.Data.dll即可,并不需要安装mysql-connector-net驱动程序;
如果使用EF的话需要安装mysql-connector-net驱动程序和mysql-for-visualstudio 这个vs里面链接数据源的插件,否则EF无法使用VS视图模型的浏览和创建以及更新数据库实体;
 
其中mysql-connector-net驱动程序安装目录包含了
MySql.Data.dll;
MySql.Data.Entity.EF5.dll;
MySql.Data.Entity.EF6.dll;
MySql.Fabric.Plugin.dll;
MySql.Web.dll;
 
注意:就算把mysql-connector-net安装目录下所有的类库都拷到bin目录而不在应用站点服务器上安装mysql-connector-net驱动程序,EF代码还是会报错,因为mysql-connector-net安装不仅装了各种dll类库,还写过机器上.net环境的全局的machine.config里加过
<system.data>
  <DbProviderFactories>
  <add name="MySQL Data Provider"
  invariant="MySql.Data.MySqlClient"
  description=".Net Framework Data Provider for MySQL"
  type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0, Culture=neutral,        PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>,
所以要使用EF必须在站点服务器安装mysql-connector-net启动程序(数据库所在的服务器不需要安装,只需要C#程序所运行的电脑需要安装)或者在应用的web.config文件里configuration节点下加上上面的配置
或者在应用所在机器的
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Config\machine.config
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
 
文件里加上上面的配置。
 
需要注意的是:当机器已经装上了mysql-connector-net驱动的时候,再加这配置就会造成name重复而报错。
 
下面给出例子:
 
using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
/*
本程序使用 MySql.Data.dll 链接Mysql数据库,读取服务器中所有数据库的名称,显示在界面上。HoverTree
*/ namespace MysqlHoverTree
{
public partial class Form1 : Form
{ private MySqlConnection _conn; public Form1()
{
InitializeComponent();
} private void button_connect_Click(object sender, EventArgs e)
{
if (_conn != null)
_conn.Close(); string h_connString = "server=localhost;user id=root; password=123456; port=3306; database=mysql; pooling=false; charset=utf8";//根据实际修改 try { _conn = new MySqlConnection(h_connString); _conn.Open(); GetDatabases(); MessageBox.Show("连接数据库成功!"); } catch (MySqlException ex) { MessageBox.Show("Error connecting to the server: " + ex.Message); }
} private void GetDatabases() { MySqlDataReader reader = null; MySqlCommand cmd = new MySqlCommand("SHOW DATABASES", _conn); try { reader = cmd.ExecuteReader(); listBox_database.Items.Clear(); while (reader.Read()) { listBox_database.Items.Add(reader.GetString()); } } catch (MySqlException ex) { MessageBox.Show("Failed to populate database list: " + ex.Message); } finally { if (reader != null) reader.Close(); } } }
}

关于mysql-connector-net和C#.net的更多相关文章

  1. 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL

    创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...

  2. vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错

    包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...

  3. Using MySQL Connector .NET 6.6.4 with Entity Framework 5

    I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new a ...

  4. [转]MySQL Connector/C++(一)

    http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...

  5. mysql.connector操作mysql的blob值

    This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...

  6. Ubuntu & MacOS安装Mysql & connector

    Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...

  7. Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

    https://geert.vanderkelen.org/2014/results-after-procedure-call/ Problem Using MySQL Connector/Pytho ...

  8. MySQL Connector/J 6.x jdbc.properties 配置, mysql-connector-java-6.0.4.jar 异常

    今天学习SSM框架整合,完成Spring和mybatis这两大框架的整合做测试时候出来很多问题,主要来自于配置文件. 我这里重点说一下Mysql数据驱动配置. 配置pom.xml时候去网站 MySQL ...

  9. mybatis/callablestatement调用存储过程mysql connector产生不必要的元数据查询

    INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProce ...

  10. 在CentOS里使用MySQL Connector/C++

    操作系统版本:CentOS6 64位 1,安装boost库.因为MySQL Connector/C++使用了boost库,所以必须先安装boost库,我们才能使用MySQL Connector/C++ ...

随机推荐

  1. 【转】Python+opencv利用sobel进行边缘检测(细节讲解)

    #! usr/bin/env python # coding:utf-8 # 2018年7月2日06:48:35 # 2018年7月2日23:11:59 import cv2 import numpy ...

  2. React的类型检测PropTypes

    React.propTypes:React.PropTypes 提供很多验证器来验证传入数据的有效性,当向props传入无效数据时,JavaScript 控制台会抛出警告. ; class MyTit ...

  3. 安卓startActivityForResult用法

    startActivityForResult的作用就是它可以回传数据,假如我们有两个页面A和B,点击A页面的一个按钮,进入下一个页面B,进入页面B后,进行设置操作,并在finish()或者back后, ...

  4. FCC(ES6写法)Pairwise

    举个例子:有一个能力数组[7,9,11,13,15],按照最佳组合值为20来计算,只有7+13和9+11两种组合.而7在数组的索引为0,13在数组的索引为3,9在数组的索引为1,11在数组的索引为2. ...

  5. JMeter 测试 ActiveMq

    JMeter 测试 ActiveMq 的资料非常少, 我花了大量的时间才研究出来 关于ActiveMq 的文章请参考我另外的文章. 阅读目录 版本号: ActiveMq 版本号:  5.91 Jmet ...

  6. [Swift]LeetCode28. 实现strStr() | Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  7. [Swift]LeetCode333. 最大的二分搜索子树 $ Largest BST Subtree

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  8. Java中 Linux下安装Redis

    1.连接上虚拟机之后,选择/usr/local目录,将redis-4.0.6.tar.gz放入/usr/local目录. 1.1:使用Xftp将redis-4.0.6.tar.gz放入/usr/loc ...

  9. Mysql的两种偏移量分页写法

    当一个查询语句偏移量offset很大的时候,如select * from table limit 10000,10 , 先获取到offset的id后,再直接使用limit size来获取数据,效率会有 ...

  10. 搭建自己的hexo博客

    这是我最近用hexo搭建的个人博客,欢迎来参观留言,以下是我创建这个hexo的一步步步骤,欢迎指正! 我的博客 参考自 潘柏信的博客;CnFeat 主题参考这里 pacman; 主题选自这里 hexa ...