在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
总的来说有三种方式: 1.ODBC :需要安装ase odbc驱动。本文里用的是ase15版本 2.OLEDB:需要安装ase oledb驱动,本文版本ase15 3.Sybase.Data.AseClient 连接 。需要Sybase.Data.AseClient.dll文件并在项目里引用。
连接字符串参考:http://www.connectionstrings.com/sybase-adaptive
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Odbc; using System.Data.OleDb; using Sybase.Data.AseClient; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DBInfo dbinfo=new DBInfo{ ip="---", port="---", u, pwd="----" }; string sql = "select Psam_id , Tel_no from Itel_reg_info"; Console.WriteLine("测试开始:"+DateTime.Now); funDll(dbinfo,sql); Console.WriteLine("DLL结束:" + DateTime.Now); funOLEDB(dbinfo,sql); Console.WriteLine("OLEDB结束:" +DateTime.Now); funODBC(dbinfo,sql); Console.WriteLine("ODBC结束:"+DateTime.Now); Console.ReadLine(); } static void funODBC(DBInfo dbinfo,string sql) { string connectionString = @"Driver={Adaptive Server Enterprise};server=" + dbinfo.ip + ";port=" + dbinfo.port + "; u; OdbcConnection myConnection = new OdbcConnection(connectionString); OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(sql, myConnection); myConnection.Open(); DataSet ds = new DataSet(); myDataAdapter.Fill(ds); } static void funOLEDB(DBInfo dbinfo,string sql) { string connectionString = @"Provider=ASEOLEDB;Data Source=" + dbinfo.ip + ":" + dbinfo.port + ";User Id=" + dbinfo.uid + ";Password=" + dbinfo.pwd + ";"; OleDbConnection myConnection = new OleDbConnection(connectionString); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(sql, myConnection); myConnection.Open(); DataSet ds = new DataSet(); myDataAdapter.Fill(ds); } static DataSet funDll(DBInfo dbinfo,string sql) { string connectionString = @"Data Source='" + dbinfo.ip + "';Port=" + dbinfo.port + ";UID='" + dbinfo.uid + "';Password='" + dbinfo.pwd + "'"; AseConnection myConnection = new AseConnection(connectionString); AseDataAdapter myDataAdapter = new AseDataAdapter(sql, myConnection); myConnection.Open(); DataSet ds = new DataSet(); myDataAdapter.Fill(ds); return ds; } } } Class DBInfo: class DBInfo { public string ip { get; set; } public string port { get; set; } public string uid { get; set; } public string pwd { get; set; } } Itel_reg_info表有40万的数据,我实验的结果是funDll 2秒完成,funOLEDB 7秒完成,funODBC 16秒完成。 最后感叹一下,ODBC太坑爹了~~~~~~~ |
请发表评论