I’m looking for best practices for establishing connections between Oracle 8 and Visual Studio 2005 applications. The target would be a Windows Forms application written in C# that hits the database once a second to monitor tables looking for their last inserted record. I’m considering using ‘Application settings’ to store the connection string there, but I’d love to hear from you guys. Thanks in advance!
This is a very rudimentary draft:
using System.Data; using System.Data.OracleClient; try { StringBuilder str = new StringBuilder(); string ora = Properties.Settings.Default.OracleConnectionString; OracleConnection con = new OracleConnection(ora); OracleCommand cmd = new OracleCommand(); cmd.Connection = con; cmd.CommandText = 'SELECT timestamp FROM jde_out WHERE rownum = 1'; cmd.CommandType = CommandType.Text; con.Open(); OracleDataReader rdr = cmd.ExecuteReader(); rdr.Read(); str.AppendLine(cmd.ExecuteScalar().ToString()); this.lblJDEtime.Text = str.ToString(); rdr.Close(); con.Close(); } catch (OracleException err) { MessageBox.Show('Exception caught:\n\n' + err.ToString()); }
I’ve just updated the code needed to perform the connection. Changed the Exception type to the more specific OracleException. Added the connection string via Properties.Settings.
Based on my experience with Oracle 10g….
I recommend using the Oracle data provider (ODP.Net) and not using the Microsoft for Oracle data provider based on my experience with Oracle 10g. Microsoft’s has not been updated in years and does not support everything in Oracle 10g, so I would definitely check into that for Oracle 8.
Following Microsoft guidance on connection string in the app.config file, you should store it like:
I’ve also worked on apps with the connection information stored in application settings, which worked fine for our application.