win7(64bit)中asp.net连接sybase

总的来说有三种方式:

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="---",
                uid="---",
                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 + "; uid=" + dbinfo.uid + ";pwd=" + dbinfo.pwd + ";";
            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太坑爹了~~~~~~~

你可能感兴趣的:(win7(64bit)中asp.net连接sybase)