码迷,mamicode.com
首页 > 数据库 > 详细

微软企业库Enterprise Library 6 连接mysql 的坑

时间:2020-02-22 10:17:15      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:common   require   XML   alarm   nbsp   inf   practice   val   field   

0.文档

  https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ff648951(v=pandp.10)?redirectedfrom=MSDN

1.DLL: (sqlserver只需前面两个)

  Microsoft.Practices.EnterpriseLibrary.Common 6.0.0.0

  Microsoft.Practices.EnterpriseLibrary.Data 6.0.0.0

  MySql.Data 6.9.9    

  安装对应版本对应系统的Mysql Connector/NET  --mysql官方网站下载               重点!重点!重点! ----大坑整了一天!

2.配置文件: 

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral,     PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <dataConfiguration defaultDatabase="mysql" />
    <connectionStrings>

       <!-- sqlserver连接字符串--> 

    <add name="sqlserver" connectionString="Data Source=mythmaomao;Initial Catalog=EntLibQuickStarts;Integrated Security=True"
      providerName="System.Data.SqlClient" />

       <!-- mysql连接字符串-->
    <add name="mysql" connectionString="server=127.0.0.1;database=IFactory;uid=root;pwd=root;Persist Security Info=True;Charset=utf8;" providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    </configuration>

3.使用:

  DatabaseProviderFactory factory = new DatabaseProviderFactory();
  //Database defaultDB = factory.Create("ExampleDatabase");
  Database defaultDB = factory.CreateDefault();

  string sql1 = @"insert into alarm_fields (FieldName,FieldDescription) values(‘xk‘,‘测试3333‘)";

  string sql = @"sekect * from alarm_fields";

  int r= defaultDB.ExecuteNonQuery(CommandType.Text, sql1);

4.# 各种封装好的方法见程序

 

微软企业库Enterprise Library 6 连接mysql 的坑

标签:common   require   XML   alarm   nbsp   inf   practice   val   field   

原文地址:https://www.cnblogs.com/hx215267863/p/12343906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!