Env: C#, .NET3.5, Oracle provider OPT.NET v11.2 Rel 3
This is a simple C# program to open an Oracle database and count the number of records in one dataset. If the program throws an exception it just silently ends with no type of error message. That is the issue - why is it not throwing an exception?
Example: There is a typo in the TNS Oracle db name wich will cause an exception on the db open command. If i use a try/catch, it detects the eror and I can display it, but if I dont use a try/catch, the program justs ends with no error message. How do I force it to display a stack trace or exception without using a try/catch. I do assume this has something to do with the oracle provider .NET interface OPT.NET behavior.
Code:
// compile:
// csc prog1.cs /r:D:\app\oracle\product\11.2.0\client_1\odp.net\bin\2.x\Oracle.DataAccess.dll
using System;
using System.Data.Common;
using Oracle.DataAccess.Client;
class OPTNetTest
{
static void Main(string[] args)
{
// Create database connection object
Console.WriteLine("Begin execution - example using Oracle Client provider.");
DbProviderFactory oraFactory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
DbConnection objDb = oraFactory.CreateConnection();
objDb.ConnectionString = "Data Source = myOraDB; User Id=user1; Password=xxx";
Console.WriteLine("Opening database.");
objDb.Open();
OracleCommand SQLCmd = (oracleCommand)oraFactory.CreateCommand();
SQLCmd.Connection = (OracleConnection)objDb;
SQLCmd.CommandText = "SELECT COUNT(*) FROM myTable";
int recCtr = Convert.ToInt32(SQLCmd.ExecuteScalar());
Console.WriteLine("Rows=" + recCtr);
objDb.Close();
objDb.Dispose();
} //end-main
} //end-class