zoukankan      html  css  js  c++  java
  • 微软企业库Enterprise Library 6 连接mysql 的坑

    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.# 各种封装好的方法见程序

  • 相关阅读:
    iOS很重要的 block回调
    怎样写具体设计文档
    ORM框架
    RapidXml用法
    【Android Training
    ORACLE触发器具体解释
    LeetCode 131 Palindrome Partitioning
    Git管理工具对照(GitBash、EGit、SourceTree)
    Android下将图片载入到内存中
    怎样破解邮箱password
  • 原文地址:https://www.cnblogs.com/hx215267863/p/12343906.html
Copyright © 2011-2022 走看看