[ Download Code ]
While this is not necessary I find it useful to separate my common functionality into it's own project. For this example I am using this utility class for my database handling. You could easily integrated thing such as sending emails, logging errors, and string functions to name a few.
In this class I have two methods and a constant string that I have defined for the database connection string. Once again I am taking advantage of the ability to define values in a single local and in the case where I define the database connection string this value is stored in the Web.config file, of which below is an example.
<?xml version="1.0" encoding="utf-8" ?>
value="User ID=userid;Password=password;Data Source=datasource" />
Now to reference this connection string in you class simply use the System.Configuration namespace. Be sure to import your ODP.NET Oracle namespaces as well.
/// Summary description for OracleDatabaseHelper.
public class OracleDatabaseHelper
// Read the connection strings from the configuration file
// Note: Modify User Id, Password, Data Source per your
// database setup this is contained with the Web.config
public static readonly string CONN_STRING =
/// Establishes your database connection
/// <returns>a database connection instance</returns>
public OracleConnection openDatabaseConnection()
OracleConnection dbConn = new OracleConnection(CONN_STRING);
public void closeDatabaseConnection(OracleConnection dbConn)
// Check if connection is open or closed
if (dbConn != null)
if (dbConn.State == ConnectionState.Open)
Now when you are ready to instantiate this class an example would be as so.
ASPAlliance.Utilities.OracleDatabaseHelper dbHelper =
In the code behind the web form you will notice when I have my database connection wrapped in a try/catch/finally statement. I will not go into the details of this rather if you are not familiar with try-catch-finally statement read Customizing Error Pages and C# Programmers Reference: try-catch-finally.
// Establish the database connection
dbConn = dbHelper.openDatabaseConnection();
// Execute the SQL Statement
NotificationLabel.Text = ex.Message;
NotificationLabel.Visible = true;
// Close the database connection
At this point you should be able to execute this application in your web browser and store an image and the other relevant information in the database and in this case the database is an Oracle instance. From here the next step is to create another web form which will display the stored images.