oracle数据库最大权限用户 如何使用 .NET访问MySQL数据库

如何使用 .NET访问MySQL数据库
NET的数据库天然支持MSSQLServer 但是并非其他数据库不支持 而是微软基于自身利益需要 在支持 营销上推自己的数据库产品;但是作为平台战略 他并非排斥其他数据库 而是参考java体系提出了一套数据库访问规范 让各个第三方进行开发 提供特定的驱动 MySQL是免费的数据库 在成本上具有无可替代的优势 但是目前来讲 并没有提供 微软把MySQL当作ODBC数据库 可以按照ODBC Net规范进行访问 具体参考 而实际上 针对ODBC Net的需要配置DSN的麻烦 而是出现了一个开源的系统MySQLDriverCS 对MySQL的开发进行了封装 实现环境下对于MySQL数据库系统的访问 通过阅读源代码 我们看到MySQLDriverCS的思路是利用C函数的底层库来操纵数据库的 通常提供对MySQL数据库的访问的数据库的C DLL是名为libmySQL dll的驱动文件 MySQLDriverCS作为一库进行封装C风格的驱动 具体如何进行呢? 打开工程后 我们看到其中有一个比较特殊的 cs文件CPrototypes cs 以下是引用片段 #region LICENSE #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( alpha )>= ) { return new MYSQL_FIELD_VERSION_ (); } else return new MYSQL_FIELD_VERSION_ (); } } public interface IMYSQL_FIELD { string Name{get;} uint Type{get;} long Max_Length {get;} } ///<summary> /// Field descriptor ///</summary> [StructLayout(LayoutKind Sequential)]// alpha internal class MYSQL_FIELD_VERSION_ : 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 _table; //public string db; ///<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_ 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;} } } ///<summary> /// Field descriptor ///</summary> [StructLayout(LayoutKind Sequential)] internal class MYSQL_FIELD_VERSION_ : IMYSQL_FIELD { ///<summary> /// Name of column ///</summary> public string name; ///<summary> /// Original column name if an alias ///</summary> public string _name; ///<summary> /// Table of column if column was a field ///</summary> public string table; ///<summary> /// Org table name if table was an alias ///</summary>
public string _table; ///<summary> /// Database for table ///</summary> public string db; ///<summary> /// Catalog for table ///</summary> //public string catalog; ///<summary> /// def ///</summary> public string def; ///<summary> /// length ///</summary> public long length; ///<summary> /// max_length ///</summary> public long max_length; ///<summary> /// name_length ///</summary> //public uint name_length; ///<summary> /// _name_length ///</summary> public uint _name_length; ///<summary> /// table_length ///</summary> public uint table_length; ///<summary> /// _table_length ///</summary> public uint _table_length; ///<summary> /// db_length ///</summary>
public string _table; ///<summary> /// Database for table ///</summary> public string db; ///<summary> /// Catalog for table ///</summary> //public string catalog; ///<summary> /// def ///</summary> public string def; ///<summary> /// length ///</summary> public long length; ///<summary> /// max_length ///</summary> public long max_length; ///<summary> /// name_length ///</summary> //public uint name_length; ///<summary> /// _name_length ///</summary> public uint _name_length; ///<summary> /// table_length ///</summary> public uint table_length; ///<summary> /// _table_length ///</summary> public uint _table_length; ///<summary> /// db_length ///</summary>
//[StructLayout(LayoutKind Explicit)] public enum enum_field_types { FIELD_TYPE_DECIMAL FIELD_TYPE_TINY FIELD_TYPE_SHORT FIELD_TYPE_LONG FIELD_TYPE_FLOAT FIELD_TYPE_DOUBLE FIELD_TYPE_NULL FIELD_TYPE_TIMESTAMP FIELD_TYPE_LONGLONG FIELD_TYPE_INT FIELD_TYPE_DATE FIELD_TYPE_TIME FIELD_TYPE_DATETIME FIELD_TYPE_YEAR FIELD_TYPE_NEWDATE FIELD_TYPE_ENUM= FIELD_TYPE_SET= FIELD_TYPE_TINY_BLOB= FIELD_TYPE_MEDIUM_BLOB= FIELD_TYPE_LONG_BLOB= FIELD_TYPE_BLOB= FIELD_TYPE_VAR_STRING= FIELD_TYPE_STRING= FIELD_TYPE_GEOMETRY= }; ///<summary> /// C prototypes warpper for mysqllib ///</summary> internal class CPrototypes { [ DllImport( libmySQL dll EntryPoint= mysql_init )] unsafe public static extern void* mysql_init(void* must_be_null); [ DllImport( libmySQL dll EntryPoint= mysql_close )] unsafe public static extern void mysql_close(void* handle); // BEGIN ADDITION BY Alex Seewald // Enables us to call mysql_option to activate pression and timeout [ DllImport( libmySQL dll EntryPoint= mysql_options )] unsafe public static extern void mysql_options(void* mysql uint option uint *value); // END ADDITION By Alex Seewald
lishixinzhi/Article/program/net/201311/11753相关文章
- oracle查询日志sql 如何查询oracle操作记录的sql
- oracle查看数据库监听 Oracle数据库监听配置
- 查看数据库表空间使用情况 Oracle数据库可用性和表空间容量
- vs中怎么创建一个数据库 如何在.NET中使用MySQL数据库
- jdbc访问数据库的步骤 .NET 访问 Oracle 数据库相关
- oracle数据库内存很高 查看ORACLE数据库内存使用情况
- oracle多表查询sql语句 oracle pl/sql 编程什么工具好用
- 数据库查询权限 Oracle用户权限查询
- 数据库创建用户并授权 Oracle创建用户权限的过程
- oracle分页查询sql语句 设置sqlplus访问远程oracle数据库的方法
爱学记

微信收款码
支付宝收款码