Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » Databases » Downloads
 
Add your own
alternative version

Custom Configuration SQL Connection String Section

, 23 Jan 2006
This solution demonstrates enforcing valid SQL connection strings in the App.Config file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- edited with XMLSpy v2006 sp2 U (http://www.altova.com) by Ted Bouskill (Ingenium Solutions BC Inc) -->
<!--W3C Schema generated by XMLSpy v2006 sp2 U (http://www.altova.com)-->
<!--
Fair License

Copyright (c) 2005 Theodore William Bouskill

Usage of the works is permitted provided that this
instrument is retained with the works, so that any entity
that uses the works is notified of this instrument.

DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:complexType name="ComputerNameType">
        <xs:annotation>
            <xs:documentation>This element represents a Computer NetBIOS or DNS Name or an IP Address</xs:documentation>
        </xs:annotation>
        <xs:choice>
            <xs:element ref="Name">
                <xs:annotation>
                    <xs:documentation>This element represents a Computer Name; IE: NetBIOS or DNS</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="IP">
                <xs:annotation>
                    <xs:documentation>This element represents a valid numeric IP address</xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="7" />
                        <xs:maxLength value="15" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:choice>
        <xs:attribute name="Port" type="xs:unsignedInt" use="optional" default="1433" />
    </xs:complexType>
    <xs:complexType name="SqlConnectionStringType">
        <xs:annotation>
            <xs:documentation>This element represents a SqlConnectionString object with the Key attribute representing the Dictionary Array key</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element ref="Authentication">
                <xs:annotation>
                    <xs:documentation>This optional sequence element is actually required if the Trust attribute in the Authentication element is false</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="ConnectionPooling" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>This optional element has attributes that represent common SQL Connection Pooling values</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="Connectivity" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>This optional element has attributes that represent common connectivity values such as Timeout</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="CurrentLanguage" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>This optional element represents the SQL Server Language to be used</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="Database">
                <xs:annotation>
                    <xs:documentation>This mandatory sequence element represents a SQL Database</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="Identification" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>This mandatory sequence element represents SQL Connection identification values</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Server" type="ComputerNameType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>This optional choice element represents the SQL Server; (local) is used by default</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="ID" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:minLength value="1" />
                    <xs:enumeration value="App.Admin" />
                    <xs:enumeration value="App.Manager" />
                    <xs:enumeration value="App.Staff" />
                    <xs:enumeration value="App.Trusted" />
                    <xs:enumeration value="App.Web" />
                    <xs:enumeration value="Log" />
                    <xs:enumeration value="Backup" />
                    <xs:enumeration value="Session" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="Required" use="optional" default="false">
            <xs:simpleType>
                <xs:restriction base="xs:boolean" />
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
    <xs:element name="Identification">
        <xs:annotation>
            <xs:documentation>This optional element represents SqlConnection identification values</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="ApplicationName" use="optional">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1" />
                        <xs:maxLength value="128" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="WorkstationID" use="optional">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1" />
                        <xs:maxLength value="64" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="ConnectionPooling">
        <xs:annotation>
            <xs:documentation>This optional element represents all SqlConnection pooling values</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="Lifetime" type="xs:unsignedLong" use="optional" default="0" />
            <xs:attribute name="Reset" use="optional" default="true">
                <xs:simpleType>
                    <xs:restriction base="xs:boolean" />
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="Enlist" type="xs:boolean" use="optional" default="true" />
            <xs:attribute name="MaxSize" type="xs:unsignedLong" use="optional" default="100" />
            <xs:attribute name="MinSize" type="xs:unsignedLong" use="optional" default="0" />
            <xs:attribute name="Pooling" use="optional" default="true">
                <xs:simpleType>
                    <xs:restriction base="xs:boolean" />
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="Connectivity">
        <xs:annotation>
            <xs:documentation>This optional element represents all SqlConnection Network values</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="NetworkLibrary" use="optional" default="dbmssocn">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="dbnmpntw" />
                        <xs:enumeration value="dbmsrpcn" />
                        <xs:enumeration value="dbmsadsn" />
                        <xs:enumeration value="dbmsgnet" />
                        <xs:enumeration value="dbmslpcn" />
                        <xs:enumeration value="dbmsspxn" />
                        <xs:enumeration value="dbmssocn" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="Timeout" type="xs:unsignedLong" use="optional" default="15" />
            <xs:attribute name="Encrypt" use="optional" default="false">
                <xs:simpleType>
                    <xs:restriction base="xs:boolean" />
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="PacketSize" type="xs:unsignedLong" use="optional" default="8192" />
        </xs:complexType>
    </xs:element>
    <xs:element name="CurrentLanguage">
        <xs:annotation>
            <xs:documentation>This optional element represents the SqlConnection language as defined by the SQL Database</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1" />
                <xs:maxLength value="128" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="Database">
        <xs:annotation>
            <xs:documentation>This mandatory element group has the required database name element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Name">
                    <xs:annotation>
                        <xs:documentation>This mandatory element is the name of SQL Database</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="File" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>This optional element is the file name of the database to attach to the SQL Server</xs:documentation>
                    </xs:annotation>
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:minLength value="4" />
                            <xs:maxLength value="160" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Name">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1" />
                <xs:maxLength value="64" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="Password">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1" />
                <xs:maxLength value="128" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="Authentication">
        <xs:annotation>
            <xs:documentation>This mandatory element represents the Authentication type for the SqlConnection</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:choice>
                <xs:element name="Trusted">
                    <xs:annotation>
                        <xs:documentation>This element choice represents a Trusted SqlConnection with no Login information required</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="LogIn">
                    <xs:annotation>
                        <xs:documentation>The element choice represents a SqlConnection that is not trusted and requires a Login Account</xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element ref="UserID">
                                <xs:annotation>
                                    <xs:documentation>This mandatory element is the User Name in the SQL Database</xs:documentation>
                                </xs:annotation>
                            </xs:element>
                            <xs:element ref="Password" minOccurs="0">
                                <xs:annotation>
                                    <xs:documentation>This optional element is the SQL Database User password</xs:documentation>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
            <xs:attribute name="Persist" use="optional" default="false">
                <xs:simpleType>
                    <xs:restriction base="xs:boolean" />
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="UserID">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1" />
                <xs:maxLength value="128" />
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="SqlConnectionStringCollection">
        <xs:annotation>
            <xs:documentation>This root element represents a Dictionary Array of SqlConnectionString objects</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="SqlConnectionString" type="SqlConnectionStringType" minOccurs="1" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation>This sequence element represents a SqlConnectionString object with the Key attribute representing the Dictionary Array key</xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:key name="SqlConnectionKey">
            <xs:selector xpath="SqlConnectionString" />
            <xs:field xpath="@ID" />
        </xs:key>
    </xs:element>
</xs:schema>

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 Code Project Open License (CPOL)

About the Author

Ted Bouskill
Software Developer (Senior)
Canada Canada
Very experienced Senior Software Developer/Manager with natural leadership and proven project management skills.
 
Started in Civil Engineering leading the integration of PC's into the Engineering process as a Design/Drafting Technician as well as an in-house Software Developer then transitioned into a full time Software Development career in the early 90's.
 
Ability to change and adapt has led to diverse experience with a wide array of technology and roles from graphics or web development to designing line of business enterprise applications.
 
Knowledge Base: Sharepoint, C#, SQL, ASP.NET, C++, CSS, HTML, JavaScript, XML, XSLT

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 24 Jan 2006
Article Copyright 2006 by Ted Bouskill
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid