Click here to Skip to main content
Licence CPOL
First Posted 31 Jul 2008
Views 16,222
Downloads 627
Bookmarked 35 times

Multiple Database Connection File Manager

By | 31 Jul 2008 | Article
Utility to manage multiple DB connection strings for an application.
 
Part of The SQL Zone sponsored by
See Also

Introduction

This application is intended to be integrated with an existing program, or become the shell of a new project that will utilize multiple database connections to Oracle and SQL Server database platforms.

Background

Many applications use a database as a backend source of data. In doing so, connecting to multiple databases is required, especially from a QA perspective. Customers also enjoy the ability to edit connections without having to edit XML or text configuration files due to the complexity of the files and lack of technical knowledge. I created this originally as a shell for a Data Generation utility for a software package I am testing. I ended up using an existing DAL that we had, so I shelved this. I decided that the effort I put into may save someone else time, so here it is.

Using the code

The code is straightforward in most areas, and is documented pretty well. I will say the XML / XPath portion is a little more complex. I want to thank Michael Chao as I used one of his programs from CodeProject as a starting base for editing the XML connection file. His article can be found here:

Here is a snippet for creating a new connection (string):

// Here is an example of the Create Connection Method using XML
private void CreateConnectionInXML()
{
    string FileNameNew = DataConnection.ConnectionFileLocation;
    
    // Determine Selected DB Type and set variable to write to xml
    int dbtypenew;                       
    if (comboBoxDBType.SelectedIndex == 0)
        dbtypenew = 1;
    else
        dbtypenew = 2;

    try
    {
        // Create an XML Reader, Open Document, Read, Close Reader
        XmlTextReader reader = new XmlTextReader(FileNameNew);
        XmlDocument docnew = new XmlDocument();
        docnew.Load(reader);
        reader.Close();
        XmlNode currNode;

        XmlDocumentFragment docFrag = docnew.CreateDocumentFragment();
        docFrag.InnerXml = "<connection>" +
            "<title>" + textBoxConnTitle.Text + "</title>" +
            "<server>" + textBoxServerName.Text + "</server>" +
            "<database>" + textBoxDatabaseName.Text + "</database>" +
            "<dbtype>" + dbtypenew  + "</dbtype>" +
            "<username>" + textBoxUsername.Text + "</username>" +
            "<password>" + textBoxPassword.Text + "</password>" +
            "</connection>";
        
        currNode = docnew.DocumentElement;
        currNode.InsertAfter(docFrag, currNode.LastChild);
        //save the output to a file 
        docnew.Save(FileNameNew);
        this.DialogResult = DialogResult.OK;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception: {0}", ex.ToString());
        this.DialogResult = DialogResult.Cancel;
    } 
}

This program was written with Visual Studio 2008 for .NET 3.5. I am sure it could be modified to work with lower versions.

Here are some screenshots:

Main Form

Edit Form

Points of interest

I will say this is my very first coding project outside of school. I am still working on the main tool I am creating, and wish I could show it here, but cannot for business reasons. I hope this helps someone, and welcome any feedback as I am just getting started in the software development field.

History

  • Version 1.0.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

TSells

Tester / Quality Assurance

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 31 Jul 2008
Article Copyright 2008 by TSells
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid