tags:

views:

1303

answers:

5

I need to know is there any feature of connecting to DB2 database from .net in .Net framework 4.0

EDIT:- I like to is there any DB2 provider

+1  A: 

What do you mean? You want something specific to .NET 4.0 or you want to know that whether we can connect with DB2 using .NET Framework or not.

If later is the case, yes you can. OleDBConnection class(which is available in .NET 2.0 and .NET 3.5 as well) has a property ConnectionString in which you set the provider's details. You simply have to give the provider's connection string for your DB2 provider and you should be OK.

Aamir
A: 

As you clarified you want a DB2 provider, see MSDN entry about HIS -- seems to match your request.

Alex Martelli
+5  A: 

Yep, the family of IBM.Data.DB2 drivers (collectively found in IBM.Data.DB2.dll, I believe) should work just fine with .NET, providing you install the drivers on your development machine.

Additionally, I was able to get it to work successfully with VS2010Beta and EF4Beta2, despite the lack of Visual Studio Add-ins for VS2010 (as of this date.) If the drivers are installed on your machine already, you just need to add an entry for it in the machine.config file for .NET 4.0's clr.

EDIT: Sample machine.config markup follows. Originally, the config file just had the single SQL server DB Provider Factory entry. Assuming you have IBM.Data.DB2 installed on your machine, you can do what I did and simply open up your 2.0's machine.config file and copy/paste the entries for DB2. Full disclosure, I honestly don't know if all 4 are required, but a clean install of 9.7fp1 inserted all four entries in my 2.0 machine.config, so I went ahead and copied them all over to 4.0 machine.config. Copy/paste, save the file, and restart visual studio 2010 and you should be able to reference the provider in your EDMX with the information in the storage model definition:

<edmx:StorageModels>
  <Schema xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" Namespace="BlahModel.Store" Alias="Self" Provider="IBM.Data.DB2" ProviderManifestToken="IDS/UNIX64, 11.50.0000">

Note that I'm interested in connecting to an informix database, hence the ProviderManifestToken value. However, I don't think that's required verbatim.

The snippet from my 4.0 machine.config:

<system.data>
    <DbProviderFactories>
        <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
        <add name="IBM DB2 .NET Data Provider" invariant="IBM.Data.DB2" description="IBM DB2 Data Provider for .NET Framework 2.0" type="IBM.Data.DB2.DB2Factory, IBM.Data.DB2, Version=9.0.0.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
        <add name="IBM Informix .NET Data Provider" invariant="IBM.Data.Informix" description="IBM Informix Data Provider for .NET Framework 2.0" type="IBM.Data.Informix.IfxFactory, IBM.Data.Informix, Version=9.0.0.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
        <add name="IBM DB2 .NET Data Provider 9.7.1" invariant="IBM.Data.DB2.9.7.1" description="IBM DB2 Data Provider 9.7.1 for .NET Framework 2.0" type="IBM.Data.DB2.DB2Factory, IBM.Data.DB2.9.7.1, Version=9.7.1.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
        <add name="IBM Informix .NET Data Provider 9.7.1" invariant="IBM.Data.Informix.9.7.1" description="IBM Informix Data Provider 9.7.1 for .NET Framework 2.0" type="IBM.Data.Informix.IfxFactory, IBM.Data.Informix.9.7.1, Version=9.7.1.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />          
    </DbProviderFactories>
</system.data>
kdawg
Can you post instructions on where to get those drivers (links, please) and then how to install them? I installed the add-in toolkit for VS2008, but I still can't see the db2 provider in the EF "Change Data Source" dialog.
camainc
Yeah, the lack of a add-in for vs2010 is what's preventing you from seeing the db2 provider in the EF dialog. I basically took a working 2008 example, upgraded it to 2010, and then made sure I added the needed entry into the machine.config for v4.0. I might have even copy/pasted the IBM db provider entry from v2.0's machine.config into v4.0's machine.config. I can't double-check, as I've since installed vs2010 RTM and haven't revisited this situation again yet.
kdawg
As a follow-up, I have since successfully connected to an Informix database via IBM.Data.DB2 with vs2010 RTM and EF4. For the record, I'm using the latest drivers (v9.7 fp1) of DB2 and still had to copy/paste the DBProvider information in 4.0 clr's machine.config
kdawg
kdawg, can you post what you added to the machine.config, and where you added it? Thanks. I don't have a previous working example to go by.
camainc
check out the edit to my original answer! =)
kdawg
Thanks, kdawg. Unfortunately I'm unable to get it working here.
camainc
what error you getting?
kdawg
A: 
I never got the visual studio add-ins working, which include the ability to add tables from the dialog in EF. Instead, I have to manually add to and edit the storage schema (SSDL) directly within the edmx XML. (Right-click the .edmx file in solution explorer, select "open with...", and choose the XML editor.)
kdawg
A: 

I had the same error with both VS2008 and VS 2010 add-in(Beta) as user336836, anyone have a suggestion?