微软企业库Enterprise Library 6 连接mysql 的坑
Posted 梦天涯#
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微软企业库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.# 各种封装好的方法见程序
以上是关于微软企业库Enterprise Library 6 连接mysql 的坑的主要内容,如果未能解决你的问题,请参考以下文章
Microsoft Enterprise Library 简介与请大家下载Microsoft Enterprise Li
VS2015|Visual Studio Enterprise 2015简体中文版(企业版)
VS2015|Visual Studio Enterprise 2015简体中文版(企业版)