Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Visual Basic

Simulating Stored Procedures in Microsoft Access using Enterprise Library Application Blocks

Rate me:
Please Sign up or sign in to vote.
3.46/5 (12 votes)
25 Jul 2005MIT6 min read 98.3K   1.1K   37  
Simulating stored procedures in Microsoft Access using Enterprise Library Application Blocks.
//===============================================================================
// Microsoft patterns & practices Enterprise Library
// Data Access Application Block
//===============================================================================
// Copyright � Microsoft Corporation. All rights reserved.
// Adapted from ACA.NET with permission from Avanade Inc.
// ACA.NET copyright � Avanade Inc. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;

namespace Microsoft.Practices.EnterpriseLibrary.Data
{
    /// <summary>
    /// <para>Represents a view for navigating the <see cref="DatabaseSettings"/> configuration data.</para>
    /// </summary>
    public class DatabaseConfigurationView : ConfigurationView
    {
        /// <summary>
        /// <para>Initialize a new instance of the <see cref="DatabaseConfigurationView"/> class with a <see cref="ConfigurationContext"/> object.</para>
        /// </summary>
        /// <param name="configurationContext">
        /// <para>A <see cref="ConfigurationContext"/> object.</para>
        /// </param>
        public DatabaseConfigurationView(ConfigurationContext configurationContext) : base(configurationContext)
        {
        }

        /// <summary>
        /// <para>Gets the <see cref="DatabaseSettings"/> configuration data.</para>
        /// </summary>
        /// <returns>
        /// <para>The <see cref="DatabaseSettings"/> configuration data.</para>
        /// </returns>
        public virtual DatabaseSettings GetDatabaseSettings()
        {
            return (DatabaseSettings)ConfigurationContext.GetConfiguration(DatabaseSettings.SectionName);
        }

        /// <summary>
        /// <para>Gets the name of the default <see cref="InstanceData"/>.</para>
        /// </summary>
        /// <returns>
        /// <para>The name of the default <see cref="InstanceData"/>.</para>
        /// </returns>
        public virtual string GetDefaultInstanceName()
        {
            DatabaseSettings settings = GetDatabaseSettings();
            string instanceName = settings.DefaultInstance;
            if (instanceName == null)
            {
                throw new ConfigurationException(SR.ExceptionMessageNoDefault);
            }
            return instanceName;
        }

        /// <summary>
        /// <para>Gets the <see cref="DatabaseProviderData"/> for the named <see cref="InstanceData"/>.</para>
        /// </summary>
        /// <param name="instanceName">
        /// <para>The name of the <see cref="InstanceData"/> to get the data.</para>
        /// </param>
        /// <returns>
        /// <para>The <see cref="DatabaseProviderData"/> for the named <see cref="InstanceData"/>.</para>
        /// </returns>
        public virtual DatabaseProviderData GetDatabaseProviderData(string instanceName)
        {
            DatabaseSettings settings = GetDatabaseSettings();
            InstanceData instance = settings.Instances[instanceName];
            if (null == instance)
            {
                throw new ConfigurationException(SR.ExceptionNoInstance(instanceName));
            }

            ConnectionStringData connectionString = settings.ConnectionStrings[instance.ConnectionString];
            if (null == connectionString)
            {
                throw new ConfigurationException(SR.ExceptionNoConnectionStringType(instance.ConnectionString));
            }

            DatabaseTypeData databaseType = settings.DatabaseTypes[instance.DatabaseTypeName];
            if (null == databaseType)
            {
                throw new ConfigurationException(SR.ExceptionNoDatabaesType(instance.DatabaseTypeName));
            }

            return new DatabaseProviderData(instance, databaseType, connectionString);
        }
        
    }
}

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, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
AiHelpWebsite.com,
LightSwitchHelpWebsite.com, and
HoloLensHelpWebsite.com.

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

Comments and Discussions