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.
- Is there something I'm overlooking, something that should be added to or removed from the Connection object when running in batch mode?
- 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();
.