microsoft提供的oledb是支持db2的,不过可能会有小bug,不过要驱动odbc可以去微软下载odbc支持的驱动.

解决方案 »

  1.   

    vs.net2003里要用oledb来连,先装db2客户端
    里面有“客户机配置辅助程序”,设置一个ODBC数据源,就OK
      

  2.   

    可是我使用oledb的方式老出错啊
      

  3.   

    Options for Connecting to DB2 from .NETHow you connect to DB2 determines what you can do. There are three techniques to connect to DB2 from .NET: 
    Using an OleDb .NET Managed Provider Both Microsoft and IBM recommend utilizing an OleDb data provider for accessing most DB2 data when either DB2 V7 or lower is used or when a COM object is the caller. Within the .NET framework, OleDb providers are exposed via COM InterOp and essentially use the same drivers available for ADO development. 
    Using an ODBC .NET Managed Provider This provides access to native ODBC drivers the same way the OLEDb .NET Data Provider provides access to native OLEDb providers. The ODBC .NET Data Provider is an add-on component to the .NET Framework. The ODBC .NET Data Provider is intended to work with all compliant ODBC drivers. 
    Using the IBM DB2 .NET Provider (Beta) This provides ADO.NET connectivity to DB2 V8.1. The DB2 .NET Data Provider is an add-in component to the Visual Studio .NET Framework. This provider accesses IBM DB2 database servers running on variety of hardware and operating system platforms. At the time of this writing, the provider is still beta but is expected to be in production soon. The DB2 .Net Data Provider provides connectivity from applications written using ADO.NET to the following DB2 family of servers: 
    DB2 Universal Database Version 8.1 running on Windows, UNIX and Linux 
    DB2 Universal Database for z/OS and OS/390 V6.1 and later using DB2 Connect V8.1 
    The different connection strings highlight the syntactical difference between scenarios. The OleDb connection string ...
    Provider=IBMDADB2.1;User ID=db2admin;Password=db2admin;Data Source=SAMPLE 
    The ODBC connection string ...
    DSN=DB2V8;UID=db2admin;PWD=db2admin 
    The IBM Managed Provider connection string ...
    Database=SAMPLE;User ID=db2admin;Password=db2admin;Server=IREK 
    Comparing Code Level AccessWhen you work with DB2 data access code, most operations are largely the same as you would expect as compared to working with other databases. Here I compare some code across connection techniques. In each of the following code snippets, we are trying to show some of the mechanics of accessing the database and managing data. Notice how the steps are the same for each technique. You start by creating the connection object, then creating a command object. In this simple example, I'm just retrieving a scalar value of the count of rows in this particular table. Finally, we execute the command's ExecuteScalar() method to return the integer. With Ole Db...
    private OleDbConnection cn = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand("SELECT COUNT(*) FROM STAFF", cn); int rc = Convert.ToInt32(cmd.ExecuteScalar()); 
    With ODBC...
    private OdbcConnection cn = new OdbcConnection(connectionString);
    OdbcCommand cmd = new OdbcCommand("SELECT COUNT(*) FROM STAFF", cn);
    int rc = Convert.ToInt32(cmd.ExecuteScalar()); 
    With IBM's Managed Provider...
    private DB2Connection cn = new DB2Connection(connectionString);
    DB2Command cmd = new DB2Command("SELECT COUNT(*) FROM STAFF", cn);
    int rc = Convert.ToInt32(cmd.ExecuteScalar()); 
    What's key here is that nothing reable or confusing is happening! 
      

  4.   

    参考:
    http://www.15seconds.com/issue/030623.htm
      

  5.   

    IBM DB2 
     OLEDB, OleDbConnection (.NET) from ms 
    TCP/IP:
    "Provider=DB2OLEDB;Network Transport Library=TCPIP;Network Address=XXX.XXX.XXX.XXX;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW" 
    o;APPC:
    "Provider=DB2OLEDB;APPC Local LU Alias=MyAlias;APPC Remote LU Alias=MyRemote;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW" 
      

  6.   

    到这里看看:
    http://www-900.ibm.com/developerWorks/cn/dmdd/index.shtml
      

  7.   

    thx,let me have a look
      

  8.   

    你安装最新板的db2回自动安装驱动,而且vs.net会多出一个db2 exploer的面板,仿制sql server的
    不过用起来感觉不大顺手
      

  9.   

    是否我还要安装这个db2的Client,到哪里下载?