Click here to Skip to main content
15,879,326 members
Articles / Web Development / ASP.NET

Object Relational Persistence in .NET

Rate me:
Please Sign up or sign in to vote.
3.94/5 (17 votes)
20 Dec 20053 min read 57.4K   374   41  
Value added object persistence scheme in .NET.
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.OracleClient;
using System.Configuration;
using System.Web.Configuration;

namespace Research
{
	public class DbConnectionStore
	{
		public static DbConnectionStore TheInstance = new DbConnectionStore();

		private DbConnectionStore()
		{
		}

		public DbConnection GetConnection(string cnHint)
		{
			ConnectionStringSettings cnSettings = DbConnectionStore.TheInstance.GetConnectionStringSettings(cnHint);
			DbProviderFactory providerFactory = DbProviderFactories.GetFactory(cnSettings.ProviderName);
			DbConnection cn = providerFactory.CreateConnection();
			cn.ConnectionString = cnSettings.ConnectionString;
			cn.Open();

			return cn;
		}

		public ConnectionStringSettings GetConnectionStringSettings(string cnHint)
		{
			ConnectionStringsSection connectionStringsSection = WebConfigurationManager.GetSection("connectionStrings") as ConnectionStringsSection;
			ConnectionStringSettingsCollection connectionStrings = connectionStringsSection.ConnectionStrings;
			ConnectionStringSettings connStringSettings = connectionStrings[cnHint];
			return connStringSettings;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions