"Invalid Argument" exception message on IBM.Data.DB2.DB2Connection .open method - c#

So I'm getting a fantastically descriptive error message of "Invalid Argument" when trying to hook up to a DB2 database. I can successfully connect to it using SQUirrel (and JDBC) using the JTopen JDBC driver with the connection string of "jdbc:as400://server;naming=system;errors=full;prompt=no"
Since the jdbc connection works, I know its a Db2.net connector issue. But the error message "Invalid Argument" frustrates any efforts into diagnosing where to begin.
string connStr = "server=server;uid=user;pwd=password";
using(DB2Connection conn=new DB2Connection(connStr))
{
conn.Open();
//System.ArgumentException: Invalid argument
// at IBM.Data.DB2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach)
// at IBM.Data.DB2.DB2Connection.set_ConnectionString(String value)
// at IBM.Data.DB2.DB2Connection..ctor(String connectionString)
// at AuroraDAL_ConnectionTests.DB2ConnectionTests.try1() in C:\Projects\...\DB2ConnectionTests.cs:line 31
// at AuroraDAL_ConnectionTests.DB2ConnectionTests.Execute() in C:\Projects\...\DB2ConnectionTests.cs:line 19
// at AuroraDAL_ConnectionTests.Program.Main(String[] args) in C:\Projects\...\Program.cs:line 20
}
Using the testconn20.exe within the DB2.net connector program files directory, I tried several options, taking the first connection string above, to then changing the shorthand keys to their longhand values, (uid changed to user id, pwd changed to password, etc)
testconn20 server=server;database=database;user id=userid;password=password
the result of that returns the same "Invalid Argument" exception eventually:
Step 1: Printing version info
.NET Framework version: 2.0.50727.5448
64-bit
DB2 .NET provider version: 9.0.0.2
Capability bits: ALLDEFINED
Build: 20090522
Factory for invairant name IBM.Data.DB2 verified
Elapsed: 0.089982
Step 2: Connecting using "server=-------;database=------;userid=------;password=------"
Invalid Argument Exception:
Connection string should be of the type 'Database=db2db; Server=mymachine:60000; User ID=db2user; Password=xxxxxxxx
Test failed.
Does anybody with some DB2 and C# have any suggestions as to what i'm doing wrong? THanks in advance.

I have no DB2 experience, but looking carefully at your code I noticed that you don't specify the Database= and the PortNumber in Server= of your connection string

It appears that IBMs site doesnt direct you to latest and greatest bits of their .net data connector. The problem was mostly solved by thoroughly looking for updates and finding their "Fix Central". This is where they keep updates and hot fixes. However it was not easy to get the right package.

finally I create the correct connection string:
Database=DBNAME;Server=IP:PORT;UID=USERNAME;Pwd=MYPASSWORD;LibraryList=LIBRARYNAME;PersistSecurityInfo=True;
For more parameters consult this: DB2Connection.ConnectionString property
https://www.ibm.com/docs/en/db2/9.7?topic=properties-connectionstring

Related

IBM.Data.DB2.Core error in new DB2Connection(connectionString)

We have the IBM.Data.DB2.Core (3.1.0.300) nuget package installed in our .netstandard2.1 application library, to connect to an external DB2 instance on prem.
On running the following code from a .net core azure function v3 Windows 64bit (from a netcoreapp3.1 project)
var connectionString= "Server=DB2_IP:DB2_Port;Database=DB2_DBNAME;UID=DB2_UserId;PWD=DB2_Password;"
var connection = new DB2Connection(connectionString);
(note the values in the connection string are placeholders for anonymity)
We are receiving the following error
IBM.Data.DB2.Core.DB2Exception (0x80004005): ERROR [58005] [IBM][DB2.NET] SQL0902 An unexpected
exception has occurred in
Process: 21308 Thread 33 AppDomain: Name:Microsoft.Azure.WebJobs.Script.WebHost
There are no context policies. Function: AESEncryptADONET (Encryption Info)
CallStack: at System.Environment.get_StackTrace()
at IBM.Data.DB2.Core.DB2ConnPool.HandleUnknownErrors(String strFncMsg, Exception exception, Boolean bThrow)
at IBM.Data.DB2.Core.DB2ConnPool.EncryptString(String value)
at IBM.Data.DB2.Core.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended)
at IBM.Data.DB2.Core.DB2Connection.set_ConnectionString(String value)
at IBM.Data.DB2.Core.DB2Connection..ctor(String connectionString)
Does anyone have any idea where we're going wrong, or alternatively have a coherent end-to-end guide on the setup that may give me a clue.
All documentations I have found thus far has been rather sparse and a little inconsistent.

SAP.Middleware.Connector.RfcSerializationException: End mark of RFCID.TableContLZ not found

I have a problem. I am trying to get data from SAP using a desktop app developed. When i connect to the VPN and run the application it runs smoothly with no errors, but when a customers try to run it from his machine it receive the folowing error and the application crashes. Can someone help me with this.
2019-03-25 15:22:29,581 [9] FATAL SAP_TO_DB.Connection - SAP.Middleware.Connector.RfcSerializationException: End mark of RFCID.TableContLZ not found. at SAP.Middleware.Connector.RfcConnection.ReadRfcIDEnd(RFCID rid) at SAP.Middleware.Connector.RfcConnection.ReadUpTo(RFCGET readState, RfcFunction function, RFCID toRid) at SAP.Middleware.Connector.RfcConnection.RfcReceive(RfcFunction function) at SAP.Middleware.Connector.RfcFunction.RfcDeserialize(RfcConnection conn, IRfcIOStream stream) at SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn, IRfcIOStream stream, RFCID rid) at SAP.Middleware.Connector.RfcFunction.RfcCallReceive(RfcConnection conn) at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination) at SAP_TO_DB.Connection.GetOnlyData(String tableName, String userName, String password, String client, String serverName, String sysNo, String optionString, Int32 rowSkips, Int32 rowCount, IRfcTable fields)
Edit: when testing on the same vpn he gets another error:
2019-03-26 14:28:16,039 [1] FATAL SAP_TO_DB.MainForm - SAP.Middleware.Connector.RfcCommunicationException: destination Custom_destination_ failed when calling RFC_METADATA_GET -- see log for details at SAP.Middleware.Connector.RfcRepository.Execute(RfcFunction function) at SAP.Middleware.Connector.RfcRepository.LookupFunctionMetadataNew(String name) at SAP.Middleware.Connector.RfcRepository.LookupFunctionMetadata(String name) at SAP.Middleware.Connector.RfcRepository.GetFunctionMetadata(String name) at SAP.Middleware.Connector.RfcRepository.CreateFunction(String name) at SAP_TO_DB.Connection.GetOnlyHeader(String tableName, String userName, String password, String client, String serverName, String sysNo, String tableFileName, Boolean isDescriptionTable) at SAP_TO_DB.MainForm.button2_Click(Object sender, EventArgs e)
There is not much about this anywhere, therefore any help is more than welcome
These are two separate problems:
First problem "End mark of RFCID.TableContLZ not found."
Most probable reason is that the data got corrupted/truncated on the network layer. If you activate RFC trace on backend side and in the .NET program, you can compare the response data that was sent by the backend and the data that was received by the .NET program. (RFC trace contains a binary network dump, if the level is high enough.)
If the traces differ, the data was modified during network transmission. If they are the same, that means the backend system already sent corrupted data. --> Open an SAP ticket in that case to have it investigated.
Second problem "Custom_destination_ failed when calling RFC_METADATA_GET"
Could it be that the parameter RfcRepository.UseRoundtripOptimization is set to true, but your customer's backend does not yet support it? (See note 1456826 for the necessary prerequisites for using this feature.)
If that is not the problem, again an RFC trace would be helpful.

getting Mono with firebird-embedded working on 64bit Linux environment

I'm trying to get Firebird-embedded 2.5 (64bit) on Linux with firebird .net provider (FirebirdSql.Data.FirebirdClient) working.
The FB embedded setup for my Test assembly is working on WinX86_64 with the Windows Firebird Embedded version.
On Linux I use the coresponding FB embedded Linux version placed files in the assembly directory:
libfbembed.so*
firebird.msg
security2.fdb
libicu*
libib*
Set the "RootDirectory" to assembly directory in the firebird.conf.
Set the shell environment variables LD_LIBRARY_PATH and FIREBIRD to to assembly directory.
FbConnectionStringBuilder conn = new FbConnectionStringBuilder();
conn.Database = #"/home/dev/firebirdTest/1stDB.FDB";
conn.ServerType = FbServerType.Embedded;
conn.UserID = "SYSDBA";
conn.Password = "masterkey";
conn.Charset = "UTF8";
conn.DataSource = "localhost";
conn.ClientLibrary = "libfbembed.so";
string connStr = conn.ConnectionString;
var dbcon = new FbConnection(connStr);
FbConnection.CreateDatabase(connStr, pageSize: 8192, forcedWrites: true, overwrite: false);
dbcon = new FbConnection(connStr);
dbcon.Open();
what I did before:
Redirecting the Firebird Clientlibrary by mono dllmap doesn't work. Solved by explicit setting the ClientLib in C# code.
manually creating a Database with isql on Linux works.
creating a Database by code on Linux works.
the Firebird .NET provider creates in debug mode the FB_{sanitizedName}.dll and DynamicAssembly.dll
the .NET provider is really silent. Debugging was done by starting the assembly with "strace mono {testAssembly.exe}" on linux.
FbConnection.CreateDatabase crashes with I/O error during "open O_CREAT" (calling FbCreateDatabase), if pagesize is not 8192. Setting explicit pagesize to 8192 solves this.
Now, I run in following errors ( and stuck here for days...):
Opening an existing Databasefile (like in the code here), crashes with:
FirebirdSql.Data.FirebirdClient.FbException: invalid database handle (no active connection) ---> invalid database handle (no active connection)
What's going wrong?
I've stuck with this error too.
FirebirdSql.Data.FirebirdClient.FbException: invalid database handle (no active connection)
Tried with FB 2.5.* and 3.0.0 results are the same.
Also tried using debug builds of FB. Logs did not help.
Maybe somebody here knows what the problem is?
It's 3 years since the original post, and I've run into the same problem. I don't have an "answer" but I do have an explanation. It appears the marshalling of SafeHandle objects isn't fully implemented in mono. From their documentation on SafeHandle: "Notice that “ref SafeHandles” pass a pointer to a slot containing zero to P/Invoked methods, and on return the a new SafeHandle is created with the returned value. “ref SafeHandles” do not actually get the original SafeHandle.handle value."
If you look into the FirebirdClient source, in IFbClient, you'll see the P/Invoke declarations look like:
IntPtr isc_detach_database(
[In, Out] IntPtr[] statusVector,
[MarshalAs(UnmanagedType.I4)] ref DatabaseHandle dbHandle);
DatabaseHandle is derived from SafeHandle, so the second argument is a "ref SafeHandle" argument, and suffers from the problem noted above - it will basically pass in a zero rather than the actual handle value.
There is no fix other than to (a) improve the SafeHandle implementation in mono, or (b) rewrite FirebirdClient to avoid the use of SafeHandles.

c# to AS400 / JD Edwards - run program - Data source name not found and no default driver specified

UPDATE: The code example below works. I changed the connection string. That was the problem. For an alternative (non-ADO) solution, see Mike Wills's link in the comments.
I have a c# class that (if I ever get it working) runs a program written in RPG code on AS/400 - JD Edwards. I know next to nothing about AS/400 and/or JD Edwards.
I've got other classes in my (intranet) web app that connect to JD Edwards, running SQL queries and setting/getting data. All of these are using the IBM.Data.DB2.iSeries dll and are working great.
For this, I wrote a similar class using the aforementioned dll, but it wasn't working. I even read somewhere online that you can't run a program using this dll. I found that a little fishy, but on suggestion from my JD Edwards co-worker, I scrapped the class and re-wrote it using the adodb dll. No data need be returned from this program run. I just want the program to run.
Here is a dummified version of the class:
private void runJDEProgram() {
ADODB.Connection cn = new ADODB.Connection();
cn.ConnectionString = "Provider=ABABAB;Data Source=111.111.111";
ADODB.Command cmdDetail = new ADODB.Command();
cn.Open(); //has to be open before setting an active connection.
cmdDetail.ActiveConnection=cn;
cmdDetail.CommandType = ADODB.CommandTypeEnum.adCmdText;
cmdDetail.CommandText = "{{CALL BLAH.BLAH(?,?)}}";
cmdDetail.Prepared = true;
cmdDetail.Parameters.Append(cmdDetail.CreateParameter("P1", ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 10, "BLAH123"));
cmdDetail.Parameters.Append(cmdDetail.CreateParameter("P2", ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 10, "BLAH456"));
object dummy = Type.Missing; //otherwise, we couldn't get past this.
cmdDetail.Execute(out dummy, ref dummy, 0);
cn.Close();
}
Here's the error I get when it runs:
{"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"}
Where am I screwing up? Thanks!
EDIT: The connection string works when querying the AS/400 to get/set data. Does it need to be modified for an operation like this, or for use with ADO?
The connection string has to be different for this, for some reason. I don't use the same connection string for the other classes that just run queries. The above connection string worked fine (with the appropriate values, of course).
It will prompt for password, but the JDE folks here wanted that.

Does LibGit2Sharp support cloning a repository from the local file system?

I am trying to clone a git repository from the local file system:
using System;
using LibGit2Sharp;
class Program
{
static void Main()
{
var sourceUrl = #"file:///c:/work/libgit2sharp";
using (Repository.Clone(sourceUrl, "targetDir", bare: true))
{
Console.WriteLine("repository successfully cloned");
}
}
}
and I get an exception:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Odb (Error).
Failed to find the memory window file to deregister
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:\work\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:\work\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:\work\libgit2sharp\LibGit2Sharp\Repository.cs:line 431
at Program.Main() in c:\work\ConsoleApplication1\Program.cs:line 10
I've also tried the following source url:
var sourceUrl = #"c:\work\libgit2sharp\.git\";
and got another exception:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Config (Error).
Failed to parse config file: Unexpected end of file while parsing multine var (in c:/work/ConsoleApplication1/bin/Debug/targetDir/config:23, column 0)
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:\work\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:\work\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:\work\libgit2sharp\LibGit2Sharp\Repository.cs:line 431
at Program.Main() in c:\work\ConsoleApplication1\Program.cs:line 12
targetDir is never created.
If on the other hand I use HTTP transport, the Repository.Clone method works fine:
var sourceUrl = "https://github.com/libgit2/libgit2sharp";
So my question is if I am doing something wrong or if this is unsupported feature or a bug in the native git2.dll?
So my question is if I am doing something wrong or if this is unsupported feature or a bug in the native git2.dll?
A bit a both, actually.
The first exception is clearly a bug. This should not happen and will be troubleshot.
The second one requires a deeper analysis. Would you be so kind as to open a issue in the LibGit2Sharp project?
Good news are that a pull request from BenStraub was recently merged. This pull request implements the local fetch transport which should pretty solve the issue.
LibGit2Sharp will be updated in the following days with a new a new version of libgit2 binaries which should allow you perform a local clone/fetch. I'll update this answer as soon as it's been done.
Update
This test shows how do to a Clone and a Push over against a local repository.

Categories

Resources