Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » SQL » Downloads
 
Add your own
alternative version
Go to top

SQL XML Documentation

, 29 Feb 2008
How to create and compile SQL XML Documentation comments
JocysComSqlScriptsGenerator.zip
DatabaseToXml
bin
Debug
JocysCom.Sql.DatabaseToXml.exe
JocysCom.Sql.DatabaseToXml.vshost.exe
JocysCom.Sql.DatabaseToXml.vshost.exe.manifest
JocysCom.Sql.XmlDocumentation.dll
JocysCom.Sql.DatabaseToXml.csproj.user
Properties
Resources
WinApp
bin
Debug
Interop.ADODB.dll
Interop.CDO.dll
JocysCom.ClassLibrary.dll
JocysCom.Sql.ScriptsGenerator.exe
JocysCom.Sql.ScriptsGenerator.vshost.exe
JocysCom.Sql.ScriptsGenerator.vshost.exe.manifest
JocysCom.Sql.XmlDocumentation.dll
Microsoft.Data.ConnectionUI.Dialog.dll
Microsoft.Data.ConnectionUI.dll
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.SqlEnum.dll
Controls
GenerateActionScripts
Jocys.com SQL Scripts Generator.csproj.user
Properties
Settings.settings
XmlDocumentation
bin
Debug
JocysCom.Sql.XmlDocumentation.dll
JocysCom.Sql.XmlDocumentation.csproj.user
Properties
SQL Scripts Generator.suo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace JocysCom.Sql.ScriptsGenerator.Controls
{
	/// <summary>
	/// ProcedureHeaders user control.
	/// </summary>
	public partial class ProcedureHeaders : UserControl
	{
		/// <summary>
		/// ProcedureHeaders.
		/// </summary>
		public ProcedureHeaders()
		{
			InitializeComponent();
			dbaConnectionString = DbaConnectionStringTextBox.Text;
			if (dbaConnectionString.Length > 0)
			{
				CreateServer();
			}
		}

        System.Data.SqlClient.SqlConnectionStringBuilder scb;
		Microsoft.SqlServer.Management.Smo.Server server;
		Microsoft.SqlServer.Management.Smo.Database database;
		Microsoft.SqlServer.Management.Smo.StoredProcedure procedure;

		#region Database Connection Strings

		/// <summary>
		/// Hide connection string password.
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		private string filterConnectionString(string text)
		{
			System.Text.RegularExpressions.Regex regex;
			regex = new System.Text.RegularExpressions.Regex("(Password|PWD)\\s*=([^;]*)([;]*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
			return regex.Replace(text, "$1=<hidden>$3");
		}

		/// <summary>
		/// Database Administrative Connection String.
		/// </summary>
		private string dbaConnectionString
		{
			get { return m_dbaConnectionString; }
			set
			{
				this.m_dbaConnectionString = value;
				DbaConnectionStringTextBox.Text = filterConnectionString(value);
			}
		}
		private string m_dbaConnectionString;

		private void DbaConnectionButton_Click(object sender, EventArgs e)
		{
			Microsoft.Data.ConnectionUI.DataConnectionDialog dcd;
			dcd = new Microsoft.Data.ConnectionUI.DataConnectionDialog();
			//Adds all the standard supported databases
			//DataSource.AddStandardDataSources(dcd);
			//allows you to add datasources, if you want to specify which will be supported 
			dcd.DataSources.Add(Microsoft.Data.ConnectionUI.DataSource.SqlDataSource);
			dcd.SetSelectedDataProvider(Microsoft.Data.ConnectionUI.DataSource.SqlDataSource, Microsoft.Data.ConnectionUI.DataProvider.SqlDataProvider);
			dcd.ConnectionString = this.dbaConnectionString;
			Microsoft.Data.ConnectionUI.DataConnectionDialog.Show(dcd);
			if (dcd.DialogResult == DialogResult.OK)
			{
				this.dbaConnectionString = dcd.ConnectionString;
                CreateServer();
            }
		}

		#endregion

		#region Interface Control

		private void CreateServer()
		{
			scb = new System.Data.SqlClient.SqlConnectionStringBuilder(this.dbaConnectionString);
            server = new Microsoft.SqlServer.Management.Smo.Server(scb.DataSource);
            FillDatabases();
		}

        public bool FillDatabases()
        {
            DatabasesListBox.Items.Clear();
            InfoLabel.Text = "";
            if (!string.IsNullOrEmpty(scb.InitialCatalog))
            {
                DatabasesListBox.Items.Add(scb.InitialCatalog);
            }
            else
            {
                int length = 0;
                try
                {
                    length = server.Databases.Count;
                }
                catch (Exception ex)
                {
                    InfoLabel.Text = DateTime.Now.ToString("HH:mm:ss") + " Database: " + ex.InnerException.Message;
                }
                for (int i = 0; i < length; i++)
                {
                    DatabasesListBox.Items.Add(server.Databases[i].Name);
                }
            }
            return true;
        }

		private void DatabasesListBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			database = server.Databases[DatabasesListBox.SelectedIndex];
			FillProcedures();
		}

		private void FillProcedures()
		{
			ProceduresListBox.Items.Clear();
			int length = database.StoredProcedures.Count;
			for (int i = 0; i < length; i++)
			{
                if (!database.StoredProcedures[i].IsSystemObject && !database.StoredProcedures[i].IsEncrypted)
				{
					ProceduresListBox.Items.Add(database.StoredProcedures[i].Name);
				}
			}
		}

		private void ProceduresListBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			procedure = database.StoredProcedures[ProceduresListBox.Text];
			LoadCurrentProcedure();
		}

		private void RegenerateCommentButton_Click(object sender, EventArgs e)
		{
			XmlDocumentation.XmlComments xc = new XmlDocumentation.XmlComments(procedure, true);
			XmlCommentsTextBox.Text = xc.ToComments("--- ", true);
		}

		#endregion

		/// <summary>
		/// Load selected procedure.
		/// </summary>
		private void LoadCurrentProcedure()
		{
			HeaderTextBox.Text = procedure.TextHeader;
			BodyTextBox.Text = procedure.TextBody;
			InfoTextBox.Clear();
			InfoTextBox.AppendText("Create Date: " + procedure.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
			InfoTextBox.AppendText("database: " + server.Information.Version.Major.ToString() + "\r\n");
			if (server.Information.Version.Major > 8)
			{
				InfoTextBox.AppendText("Date Last Modified: " + procedure.DateLastModified.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
				InfoTextBox.AppendText("Method Name: " + procedure.MethodName + "\r\n");
			}
			InfoTextBox.AppendText("Extended Propereties: " + procedure.ExtendedProperties.Count.ToString() + "\r\n");
			InfoTextBox.AppendText("Name: " + procedure.Name + "\r\n");
			InfoTextBox.AppendText("Parameters Count: " + procedure.Parameters.Count.ToString() + "\r\n");
			for (int i = 0; i < procedure.Parameters.Count; i++)
			{

				InfoTextBox.AppendText("\t" + SqlObjectsToString.GetParameterWithType(procedure.Parameters[i]) + "\r\n");
			}
			InfoTextBox.AppendText("Properties Count: " + procedure.Properties.Count.ToString() + "\r\n");
			for (int i = 0; i < procedure.Properties.Count; i++)
			{
				InfoTextBox.AppendText("\t" + procedure.Properties[i].Name + " = " + procedure.Properties[i].Value.ToString() + "\r\n");
			}
			// Load XML Comments;
			string procedureText = procedure.Properties["Text"].Value.ToString();
			XmlDocumentation.XmlComments xc = new XmlDocumentation.XmlComments(procedure);
			XmlCommentsTextBox.Text = ((XmlDocument)xc.AllComments).DocumentElement.OuterXml;
		}

	}
}

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)

Share

About the Author

EJocys
Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 29 Feb 2008
Article Copyright 2007 by EJocys
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid