Click here to Skip to main content
12,509,728 members (48,622 online)
Click here to Skip to main content

Stats

69.8K views
1K downloads
29 bookmarked
Posted

Strategy to distribute secure database connection strings in an enterprise environment

, 29 Nov 2003
The article discusses a strategy to securely configure and administer a set of connection strings which can be maintained environment wise. It also talks about distributing this information securely in a huge environment to be used by authorized clients only.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using EnterpriseConnString;

namespace UseECS
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class TestClientECS : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox serverTxt;
		private System.Windows.Forms.TextBox keywordTxt;
		private System.Windows.Forms.TextBox envTxt;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Button GetConnStrBtn;
		private System.Windows.Forms.Button CloseBtn;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox connStrTxt;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TestClientECS()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TestClientECS));
			this.label1 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.serverTxt = new System.Windows.Forms.TextBox();
			this.keywordTxt = new System.Windows.Forms.TextBox();
			this.envTxt = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.GetConnStrBtn = new System.Windows.Forms.Button();
			this.connStrTxt = new System.Windows.Forms.TextBox();
			this.CloseBtn = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(42, 10);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(44, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Server :";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(32, 74);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(54, 16);
			this.label4.TabIndex = 3;
			this.label4.Text = "Keyword :";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(12, 20);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(74, 16);
			this.label5.TabIndex = 4;
			this.label5.Text = "Environment :";
			// 
			// serverTxt
			// 
			this.serverTxt.Location = new System.Drawing.Point(90, 8);
			this.serverTxt.Name = "serverTxt";
			this.serverTxt.Size = new System.Drawing.Size(174, 20);
			this.serverTxt.TabIndex = 1;
			this.serverTxt.Text = "";
			// 
			// keywordTxt
			// 
			this.keywordTxt.Location = new System.Drawing.Point(90, 72);
			this.keywordTxt.Name = "keywordTxt";
			this.keywordTxt.ReadOnly = true;
			this.keywordTxt.Size = new System.Drawing.Size(174, 20);
			this.keywordTxt.TabIndex = 2;
			this.keywordTxt.Text = "";
			// 
			// envTxt
			// 
			this.envTxt.Location = new System.Drawing.Point(88, 18);
			this.envTxt.Name = "envTxt";
			this.envTxt.Size = new System.Drawing.Size(174, 20);
			this.envTxt.TabIndex = 3;
			this.envTxt.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(12, 36);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(254, 28);
			this.label6.TabIndex = 10;
			this.label6.Text = "User should have read permissions on server Registy keys. Leave server blank for " +
				"localhost.";
			// 
			// GetConnStrBtn
			// 
			this.GetConnStrBtn.Location = new System.Drawing.Point(73, 72);
			this.GetConnStrBtn.Name = "GetConnStrBtn";
			this.GetConnStrBtn.Size = new System.Drawing.Size(122, 23);
			this.GetConnStrBtn.TabIndex = 5;
			this.GetConnStrBtn.Text = "Get connection string";
			this.GetConnStrBtn.Click += new System.EventHandler(this.GetConnStrBtn_Click);
			// 
			// connStrTxt
			// 
			this.connStrTxt.Location = new System.Drawing.Point(6, 48);
			this.connStrTxt.Name = "connStrTxt";
			this.connStrTxt.ReadOnly = true;
			this.connStrTxt.Size = new System.Drawing.Size(256, 20);
			this.connStrTxt.TabIndex = 4;
			this.connStrTxt.Text = "";
			// 
			// CloseBtn
			// 
			this.CloseBtn.BackColor = System.Drawing.SystemColors.Control;
			this.CloseBtn.Location = new System.Drawing.Point(77, 210);
			this.CloseBtn.Name = "CloseBtn";
			this.CloseBtn.Size = new System.Drawing.Size(122, 23);
			this.CloseBtn.TabIndex = 6;
			this.CloseBtn.Text = "Exit";
			this.CloseBtn.Click += new System.EventHandler(this.CloseBtn_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.envTxt);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.connStrTxt);
			this.groupBox1.Controls.Add(this.GetConnStrBtn);
			this.groupBox1.Location = new System.Drawing.Point(4, 98);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(268, 104);
			this.groupBox1.TabIndex = 15;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Connection string";
			// 
			// TestClientECS
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(276, 243);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.CloseBtn);
			this.Controls.Add(this.keywordTxt);
			this.Controls.Add(this.serverTxt);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "TestClientECS";
			this.Text = "     Test Enterprise Connection String";
			this.Load += new System.EventHandler(this.OnLoad);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void CloseBtn_Click(object sender, System.EventArgs e)
		{
			Close();
		}

		private void OnLoad(object sender, System.EventArgs e)
		{
			try 
			{
				this.keywordTxt.Text = Keyword.GetKeyWord();
			}
			catch(Exception ex) // error - the keyword is not set on this machine
			{
				MessageBox.Show(ex.Message, "Error");
				Close();
			}
		}

		// required client code to get a connection string
		private void GetConnStrBtn_Click(object sender, System.EventArgs e)
		{
			try
			{
				EntConnString connstr = new EntConnString(serverTxt.Text);
				connstr.Connect();
				connStrTxt.Text = connstr.GetConnectionString(envTxt.Text);
			}
			catch (Exception ex) 
			{
				MessageBox.Show(ex.Message, "Error");
			}
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sriram Chitturi
Architect
United States United States
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 30 Nov 2003
Article Copyright 2003 by Sriram Chitturi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid