Click here to Skip to main content
15,881,559 members
Articles / Programming Languages / XSLT

Custom Configuration SQL Connection String Section

Rate me:
Please Sign up or sign in to vote.
3.42/5 (7 votes)
23 Jan 2006CPOL5 min read 90.2K   1K   24  
This solution demonstrates enforcing valid SQL connection strings in the App.Config file.
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="Authentication">
		<xsl:if test="@Persist = 'true'">Persist Security Info=True; </xsl:if>
		<xsl:if test="Trusted">Integrated Security=True; </xsl:if>
		<xsl:apply-templates select="LogIn"/>
	</xsl:template>
	<xsl:template match="Authentication/LogIn">
		<xsl:if test="UserID">User ID=<xsl:value-of select="UserID"/>; </xsl:if>
		<xsl:if test="Password">Password=<xsl:value-of select="Password"/>; </xsl:if>
	</xsl:template>
	<xsl:template match="ConnectionPooling">
		<xsl:if test="@Enlist != 'true'">Enlist=<xsl:value-of select="@Enlist"/>; </xsl:if>
		<xsl:if test="@Lifetime != '0'">Connection Lifetime=<xsl:value-of select="@Lifetime"/>; </xsl:if>
		<xsl:if test="@MinSize != '0'">Min Pool Size=<xsl:value-of select="@MinSize"/>; </xsl:if>
		<xsl:if test="@MaxSize != '100'">Max Pool Size=<xsl:value-of select="@MaxSize"/>; </xsl:if>
		<xsl:if test="@Pooling != 'true'">Pooling=<xsl:value-of select="@Pooling"/>; </xsl:if>
		<xsl:if test="@Reset != 'true'">Connection Reset=<xsl:value-of select="@Reset"/>; </xsl:if>
	</xsl:template>
	<xsl:template match="Connectivity">
		<xsl:if test="@Encrypt != 'false'">Encrypt=<xsl:value-of select="@Encrypt"/>; </xsl:if>
		<xsl:if test="@NetworkLibrary != 'dbmssocn'">Network Library=<xsl:value-of select="@NetworkLibrary"/>; </xsl:if>
		<xsl:if test="@PacketSize != '8192'">Packet Size=<xsl:value-of select="@PacketSize"/>; </xsl:if>
		<xsl:if test="@Timeout">Connection Timeout=<xsl:value-of select="@Timeout"/>; </xsl:if>
	</xsl:template>
	<xsl:template match="Database">
		<xsl:if test="Name">Database=<xsl:value-of select="Name"/>; </xsl:if>
		<xsl:if test="File">AttachDBFilename=<xsl:value-of select="File"/>; </xsl:if>
	</xsl:template>
	<xsl:template match="Identification">
		<xsl:if test="@ApplicationName">Application Name=<xsl:value-of select="@ApplicationName"/>; </xsl:if>
		<xsl:if test="@WorkstationID">Workstation ID=<xsl:value-of select="@WorkstationID"/>; </xsl:if>
	</xsl:template>
	<xsl:template match="Server">
		<xsl:choose>
			<xsl:when test="Name">Server=<xsl:value-of select="Name"/></xsl:when>
			<xsl:when test="IP">Network Address=<xsl:value-of select="IP"/></xsl:when>
		</xsl:choose>
		<xsl:if test="@Port != '1433'">,<xsl:value-of select="@Port"/></xsl:if>;</xsl:template>
</xsl:stylesheet>

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)


Written By
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

Comments and Discussions