Connect to Database DB2

Hi Everyone,

I want to connect to a DB2 database without setting up ODBC on my machine OR to say I want no dependency over ODBC for database.

Can anyone guide how can I do that?

I tried below things but getting errors -

Tried below VB.net code

' Create a connection string
Dim connectionString As String = "Server=myServerAddress;Database=myDatabase;UID=myUsername;PWD=myPassword;"

' Create a DB2Connection object
Using connection As New DB2Connection(connectionString)
    ' Open the connection
    connection.Open()

    ' Execute SQL commands or perform database operations
    Dim sql As String = "SELECT * FROM TableName"
    Using command As New DB2Command(sql, connection)
        Using reader As DB2DataReader = command.ExecuteReader()
            ' Process the retrieved data
            While reader.Read()
                ' Access the data using reader.GetString(), reader.GetInt32(), etc.
                ' Perform any required actions within the loop
            End While
        End Using
    End Using

    ' Close the connection
    connection.Close()
End Using

But this code is giving error that Type not defined for DB2Connection and DB2Command, this might be because I am not able to import IBM.DATA.DB2 dependency in my studio as it is not available in Manage packages. I installed IBM.Data.DB2.EntityFrameWork but that is not working.

Can anyone please help me with some solutions?

@Yoichi @ppr

Fine
Here you can use the open-source ADO.NET provider called "IBM.Data.DB2.Core.

But why don’t want To use ODBC which will be easy though

vbnet
Copy code
' Import the necessary namespaces
Imports IBM.Data.DB2.Core
Imports IBM.Data.DB2.Core.Common

' Create a connection string
Dim connectionString As String = "Server=myServerAddress;Database=myDatabase;UserID=myUsername;Password=myPassword;"

' Create a DB2Connection object
Using connection As New DB2Connection(connectionString)
    ' Open the connection
    connection.Open()

    ' Execute SQL commands or perform database operations
    Dim sql As String = "SELECT * FROM TableName"
    Using command As New DB2Command(sql, connection)
        Using reader As DB2DataReader = command.ExecuteReader()
            ' Process the retrieved data
            While reader.Read()
                ' Access the data using reader.GetString(), reader.GetInt32(), etc.
                ' Perform any required actions within the loop
            End While
        End Using
    End Using

    ' Close the connection
    connection.Close()
End Using

Hope this helps

Cheers @Dhruvi_Arumugam

Hi @Palaniyappan

Thanks for this but I have already tried this Imports thing and I get this below error
image

Also, I am not using ODBC as part of client requirement.

Can you please suggest something else as the solution.

Thanks!