.NET的数据库天然支持MSSQLServer,但是并非其他数据库不支持,而是微软基于自身利益需要,在支持、营销上推自己的数据库产品;但是作为平台战略,他并非排斥其他数据库,而是参考java体系提出了一套数据库访问规范,让各个第三方进行研发,提供特定的驱动。
MySQL是免费的数据库,在成本上具备无可替代的优势,但是现在来讲,并没有提供。微软把MySQL当作ODBC数据库,能够按照ODBC.Net规范进行访问,具体参考http://www.microsoft.com/china/community/Columns/Luyan/6.mspx
而实际上,针对ODBC。Net的需要配置DSN的麻烦,而是出现了一个开源的系统MySQLDriverCS,对MySQL的研发进行了封装,实现了.net环境下对于MySQL数据库系统的访问。http://sourceforge.net/projects/mysqldrivercs/
通过阅读源代码,我们看到MySQLDriverCS的思路是利用C函数的底层库来操纵数据库的,通常提供对MySQL数据库的访问的数据库的C DLL是名为libmySQL.dll的驱动文档,MySQLDriverCS作为一个.net库进行封装C风格的驱动。
具体如何进行呢?
打开工程后,我们看到其中有一个比较特别的.cs文档CPrototypes.cs:
| #region LICENSE /* MySQLDriverCS: An C# driver for MySQL. Copyright (c) 2002 Manuel Lucas Vi馻s Livschitz. This file is part of MySQLDriverCS. MySQLDriverCS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MySQLDriverCS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MySQLDriverCS; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #endregion using System; using System.Data; using System.Runtime.InteropServices; namespace MySQLDriverCS { //[StructLayout(LayoutKind.Sequential)] public class MYSQL_FIELD_FACTORY { static string version; public static IMYSQL_FIELD GetInstance() { if (version==null) { version = CPrototypes.GetClientInfo(); } if (version.CompareTo("4.1.2-alpha")>=0) { return new MYSQL_FIELD_VERSION_5(); } else return new MYSQL_FIELD_VERSION_3(); } } public interface IMYSQL_FIELD { string Name{get;} uint Type{get;} long Max_Length {get;} } ///<summary> /// Field descriptor ///</summary> [StructLayout(LayoutKind.Sequential)]//"3.23.32", 4.0.1-alpha internal class MYSQL_FIELD_VERSION_3: IMYSQL_FIELD { ///<summary> /// Name of column ///</summary> public string name; ///<summary> /// Table of column if column was a field ///</summary> public string table; //public string org_table; /* Org table name if table was an alias */ //public string db; /* Database for table */ ///<summary> /// def ///</summary> public string def; ///<summary> /// length ///</summary> public long length; ///<summary> /// max_length ///</summary> public long max_length; ///<summary> /// Div flags ///</summary> public uint flags; ///<summary> /// Number of decimals in field ///</summary> public uint decimals; ///<summary> /// Type of field. Se mysql_com.h for types ///</summary> public uint type; ///<summary> /// Name ///</summary> public string Name { get{return name;} } ///<summary> /// Type ///</summary> public uint Type { get{return type;} } ///<summary> /// Max_Length ///</summary> public long Max_Length { get {return max_length;} } }
文章整理:西部数码--专业提供域名注册、虚拟主机服务 相关文章
热点关注
IDC资讯
虚拟主机
域名注册
托管租用
vps主机
智能建站
网站运营 建站经验 策划盈利 搜索优化 网站推广 免费资源 网站联盟 联盟新闻 联盟介绍 联盟点评 网赚技巧 行业资讯 业界动态 搜索引擎 网络游戏 门户动态 电子商务 广告传媒 网络编程 Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它 服务器技术 Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护 软件技巧 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 Internet Explorer 网页制作 FrontPages Dreamweaver Javascript css photoshop fireworks Flash 程序设计 Java技术 C/C++ VB delphi 网络知识 网络协议 网络安全 网络管理 组网方案 Cisco技术 操作系统 Win2000 WinXP Win2003 Mac OS Linux FreeBSD |




