I didn't figure out how to download the license for my DB2 for i.
So far the error message of the connection string is not about the license issue. If it can go further to complain about the license issue. I will check this back.
Original Message:
Sent: Thu June 29, 2023 03:37 PM
From: Jan Nelken
Subject: Connect from .NET6
I am making a far stretching assumptions :-)
IP address of I-series server is correct;
port number of I-series server is correct;
There is a listener on I series which is actively listening on IP Address:port as described above;
There is no firewall rules blocking access to above mentione ip:port.
If you double checked and verified all that (and telnet session to ip:port appears to be connecting) then you may explore applying Db2 Connect license.
Perhaps this be of any assistance:
https://www.ibm.com/docs/en/db2/11.5?topic=li-activating-license-certificate-file-db2-connect-unlimited-edition
------------------------------
Jan Nelken
Original Message:
Sent: Thu June 29, 2023 12:01 PM
From: Bruce Ma
Subject: Connect from .NET6
Hi Jan,
Yes, IBM i and my development PC are on the same network 192.168.1.0.
Thanks,
Bruce
------------------------------
Bruce Ma
Original Message:
Sent: Wed June 28, 2023 04:58 PM
From: Jan Nelken
Subject: Connect from .NET6
Are you sure that your IBM I-series server is on the same network? You used 192.168.1.239 as IP address of database server ...
------------------------------
Jan Nelken
Original Message:
Sent: Wed June 28, 2023 03:12 PM
From: Bruce Ma
Subject: Connect from .NET6
Hi Youssef,
i deleted the package IBM.Data.DB2.Core and installed the package Net.IBM.Data.Db2 (7.0.0.200, i assume you meant this package because I couldn't find package IBM.Data.DB2).
In code section, except using part, only the connection string was changed. i use the connection string "DataSource=192.168.1.239;UserID=MyUserId;Password=MyPassword;". The program errored out at using (DB2Connection connection = new DB2Connection(connectionString))
The error message is:
System.ArgumentException
HResult=0x80070057
Message=Invalid argument
Source=IBM.Data.Db2
StackTrace:
at IBM.Data.Db2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended)
at IBM.Data.Db2.DB2Connection.set_ConnectionString(String value)
at IBM.Data.Db2.DB2Connection..ctor(String connectionString)
at Program.<Main>$(String[] args) in C:\TestProject\ApiTest\ApiTest\Program.cs:line 11
This exception was originally thrown at this call stack:
[External Code]
Program.<Main>$(string[]) in Program.cs
if i use the connection string "Server=192.168.1.239;Database=S2151CCW;UID=MyUserID;PWD=MyPassword;", the program errored out at connection.Open()
The error message is:
IBM.Data.Db2.DB2Exception
HResult=0x80004005
Message=External component has thrown an exception.
Source=IBM.Data.Db2
StackTrace:
at IBM.Data.Db2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
at IBM.Data.Db2.DB2Connection.Open()
at Program.<Main>$(String[] args) in C:\TestProject\ApiTest\ApiTest\Program.cs:line 14
This exception was originally thrown at this call stack:
[External Code]
Program.<Main>$(string[]) in Program.cs
Another question is: does it need db2 connection license? if yes, how can i get the license (better for a temporary license because i want to try first of all)?
Can you please help me with this?
Bruce
------------------------------
Bruce Ma
Original Message:
Sent: Wed June 28, 2023 08:43 AM
From: Youssef Sbai Idrissi
Subject: Connect from .NET6
Hey bruce,
that's an important clarification.
You need to make some adjustments for the code I showed before, for IBM i we use IBM.Data.DB2 instead of IBM.Data.DB2.core, and that changes some things, I hope this goes smoothly for you :
using System;using IBM.Data.DB2;namespace Db2ConnectionExample{ class Program { static void Main(string[] args) { string connectionString = "DataSource=myServerAddress;UserID=myUsername;Password=myPassword;"; try { using (DB2Connection connection = new DB2Connection(connectionString)) { connection.Open(); using (DB2Command command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM your_table"; using (DB2DataReader reader = command.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); Console.WriteLine($"ID: {id}, Name: {name}"); } } } } } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } }}
------------------------------
Youssef Sbai Idrissi
Software Engineer
Original Message:
Sent: Tue June 27, 2023 12:44 PM
From: Bruce Ma
Subject: Connect from .NET6
Hi Youssef,
I might need to clarify that my DB2 server is IBM i. OS version is V7.4
I appreciate any help.
Bruce
------------------------------
Bruce Ma
Original Message:
Sent: Tue June 27, 2023 10:30 AM
From: Youssef Sbai Idrissi
Subject: Connect from .NET6
Hey Bjorn,
To connect to an IBM Db2 database from a .NET 6 application, you can use the IBM.Data.DB2.Core package, which provides the necessary functionality for establishing a connection and interacting with the database. Here's a sample code to guide you on how to connect to Db2 from .NET :
using System;using IBM.Data.DB2.Core;namespace Db2ConnectionExample{ class Program { static void Main(string[] args) { string connectionString = "Server=myServerAddress;Database=myDatabase;UID=myUsername;PWD=myPassword;"; try { using (Db2Connection connection = new Db2Connection(connectionString)) { connection.Open(); using (Db2Command command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM your_table"; using (Db2DataReader reader = command.ExecuteReader()) { while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); Console.WriteLine($"ID: {id}, Name: {name}"); } } } } } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } }}
I hope this helps you !
------------------------------
Youssef Sbai Idrissi
Software Engineer
Original Message:
Sent: Mon June 20, 2022 03:48 AM
From: Björn Holmgren
Subject: Connect from .NET6
We have a customer with a Db2 based business system. and we want to develop a .NET 6 application for them, and connect to the Db2 database. I have never worked with IBM Db2 before, and need some help. I have tried installed the IBM NuGet Db2.core, for .NET 6 but it throws errors when I try connect, it throws on the Open command even. So...
Question: Exactly how do I connect to Db2 from .NET6?
------------------------------
Björn Holmgren
------------------------------
#Db2