0

We have an interactive WPF application on .Net 5.0 for Windows that we now need to be able to launch in batch mode.

I've duly added a test on e.Args (from App.OnStartup()): if e.Args[0] has the expected value, the main process launches directly instead of being launched by the click of a button.

I tweaked the main process to have it just write a line in a file, to test that the simulated launch in batch mode did what it was supposed to do.

Then, I de-tweaked it and let it run.

The first occurrence of OleDbConnection.Open() crashes the application from inside a try ... catch block and nothing is actually caught.

Funnier still, the Output window says "The program has exited with code 0 (0x0)."

The application uses OleDbConnection to connect to two distinct databases, one on Oracle and a legacy one on Sybase. I've tried it with both connections and both crash the same way.

When I take away the argument and run it in interactive mode, OleDbConnection.Open() works like a charm.

We have at least one other application that runs and works fine in both modes. The main difference with my own is that it's written in old VB and Forms (.Net Framework 4.8), with patches of C# where we've been able to add them.

  1. Is there something I'm overlooking, something that should be added to or removed from the Connection object when running in batch mode?
  2. How come the try ... catch doesn't actually catch the error?

EDIT: I didn't include a minimal, reproducible example because I didn't see how it would help. Here it is:

System.Data.OleDb.OleDbConnection z_cnxTest = new("Server Port Address=5000;Server Name=some.server.name;Row Cache Size=50;Optimize Prepare=Partial;Enable Quoted Identifiers=0;Print Statement Behavior=MS Compatible;Network Protocol=Winsock;Raise Error Behavior=MS Compatible;Password=drowssapasisiht;Extended ErrorInfo=FALSE;Stored Proc Row Count=Last Statement Only;Provider=Sybase.ASEOLEDBProvider;WorkStation ID=MyWorkStationID;Default Length For Long Data=1024;Packet Size=1;Select Method=cursor;User ID=ThisUser;Initial Catalog=DataBaseName;Trusted_Connection=yes;connection reset=false;connection lifetime=120;enlist=true;min pool size=1;max pool size=50;OLE DB Services=-1");
z_cnxTest.Open();
z_cnxTest.Close();
z_cnxTest.Dispose();

Pretty standard, as you can see. The process crashes at z_cnxTest.Open();.

Jean-David Lanz
  • 865
  • 9
  • 18
  • _Is there something I'm overlooking_: The first thing I noticed is that your asking why your code fails, but your post is missing a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) which others can use to re-create the issue that you're facing. – Tu deschizi eu inchid Feb 08 '22 at 17:34
  • 1
    It's not clear why you've chosen to use OleDb to connect to Oracle. You should consider using NuGet package [Oracle.ManagedDataAccess.Core](https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/). This [post](https://stackoverflow.com/questions/68591698/program-not-responding-when-executing-oracledataadapter-fill/68595986#68595986) may be helpful (it's in VB.NET, but should be easy to convert). – Tu deschizi eu inchid Feb 08 '22 at 17:42
  • @user9938: thanks for taking the time. I've added the example. I wasn't aware of that NuGet package and it might help for sure, I'll try it. I'll also have to try and find something for Sybase, of course. – Jean-David Lanz Feb 09 '22 at 08:45
  • 1
    For Sybase, the following may be helpful: https://stackoverflow.com/questions/6463019/is-there-anyway-to-connect-to-sybase-from-c-sharp-without-having-to-add-a-odbc-d and https://help.sap.com/viewer/54c3945e6dd14033889f875bed1323ce/16.0.4/en-US/b11f144abbf91014a975fd094e76b4ad.html?q=download%20SAP%20Adaptive%20Server%20sdk – Tu deschizi eu inchid Feb 09 '22 at 18:58
  • ... Welp, I'm a dumbass. The program wasn't crashing, it was _exiting_. See, in interactive mode the actual process was launched on a different thread so the UI thread could display the progress bar and message. When in batch mode, the process was still launched on a different thread, but there was no UI to stop the application from exiting. Now the process is launched in the main thread in batch mode and everything seems to go fine. – Jean-David Lanz Feb 10 '22 at 14:14
  • @user9938: thanks for your help and sorry for wasting your time on this. – Jean-David Lanz Feb 10 '22 at 14:15

0 Answers0