Click here to Skip to main content
15,888,984 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.
// 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.
//===============================================================================

#if UNIT_TESTS
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Design.Tests
{
    public sealed class DatabaseSettingsBuilder
    {
        private static readonly string xmlString =
            "<enterpriseLibrary.databaseSettings xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data\" defaultInstance=\"Service_Dflt\">" +
                "<databaseTypes>" +
                "<databaseType name=\"SqlServer\" type=\"" + typeof(SqlDatabase).AssemblyQualifiedName + "\" />" +
                "<databaseType name=\"Oracle\" type=\"" + typeof(OracleDatabase).AssemblyQualifiedName + "\" />" +
                "</databaseTypes>" +
                "<connectionStrings>" +
                "<connectionString name=\"Northwind\">" +
                "<parameters>" +
                "<parameter name=\"server\" value=\"localhost\" />" +
                "<parameter name=\"user id\" value=\"Northwind\" />" +
                "<parameter name=\"Integrated Security\" value=\"true\" />" +
                "</parameters>" +
                "</connectionString>" +
                "<connectionString xsi:type=\"OracleConnectionStringData\" " +
                "name=\"OracleConnection\">" +
                "<parameters>" +
                "<parameter name=\"server\" value=\"entlib\" />" +
                "<parameter name=\"database\" value=\"testuser\" />" +
                "<parameter name=\"password\" value=\"testuser\" />" +
                "</parameters>" +
                "<packages>" +
                "<package prefix=\"MyStoredProc\" name=\"ENTLIB\" />" +
                "</packages>" +
                "</connectionString>" +
                "</connectionStrings>" +
                "<instances>" +
                "<instance name=\"NewDatabase\" type=\"SqlServer\" connectionString=\"Northwind\"/>" +
                "<instance name=\"Service_Dflt\" type=\"SqlServer\" connectionString=\"Northwind\"/>" +
                "<instance name=\"DbWithSqlServerAuthn\" type=\"SqlServer\" connectionString=\"Northwind\"/>" +
                "</instances>" +
                "</enterpriseLibrary.databaseSettings>";

        private DatabaseSettingsBuilder()
        {
        }

        public static DatabaseSettings Create(IServiceProvider serviceProvider)
        {
            INodeCreationService nodeCreationService = ServiceHelper.GetNodeCreationService(serviceProvider);

            Type nodeType = typeof(OracleConnectionStringNode);
            NodeCreationEntry entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(serviceProvider, nodeType), nodeType, typeof(OracleConnectionStringData), SR.OracleConnectionStringNodeFriendlyName);
            nodeCreationService.AddNodeCreationEntry(entry);

            nodeType = typeof(ConnectionStringNode);
            entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(serviceProvider, nodeType), nodeType, typeof(ConnectionStringData), SR.ConnectionStringNodeFriendlyName);
            nodeCreationService.AddNodeCreationEntry(entry);
            
            XmlTextReader xmlReader = new XmlTextReader(new StringReader(xmlString));
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(DatabaseSettings));
            return xmlSerializer.Deserialize(xmlReader) as DatabaseSettings;
        }
    }
}

#endif

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