Click here to Skip to main content
13,289,626 members (60,110 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 21 Feb 2004

QASharp V1.1 [Query Analyzer like tool for MSDE database]

, 21 Feb 2004
Rate this:
Please Sign up or sign in to vote.
This project is meant to provide a tool similar to query analyzer which can be used to execute queries, create tables and do all other common database activities.

Sample Image - QASharp.jpg

Sample screenshot


The QASharp V.1.1 was developed for those using the MSDE (Microsoft Desktop Engine). This project is meant to provide a tool similar to query analyzer which can be used to execute queries, create tables and all other common database activities. This is still in its first release and this is my first attempt at developing a utility entirely in C#, and also my first article to Code Project. The code is not at all optimized. My purpose for the first release is to get a working tool.

All suggestions, apprehensions, criticisms are welcome.


SqlDBHandler.cs by ASP Enterprise Manager.

Functionality Supported

  • Create new query
  • Save existing query
  • Open existing query
  • Execute queries
  • Multiple query output window
  • Connect to different data sources
  • Syntax highlighting of major keywords
  • Added 'Show Errors' in Help menu

Configuration settings to be made

In order for the application to work, make the following changes in the app.config file in the keys listed below:

<?xml version="1.0" encoding="Windows-1252"?>
    <add key="server" value="(local)" /> 
    <add key ="database" value="master" />
          <add key="uid" value="sa"/>
          <add key="pwd" value=""/> 
ServerThe server to connect to
DatabaseThe initial database to connect to
UidUser id
Pwd Password


  • Select a database
  • Create a new document by clicking on New
  • Type in the query (for multiple queries, add a “GO” keyword after each query)
  • Press “F5” to execute query or click on the execute icon on the toolbar.

To select a different server: Click on File-> Connect. Enter the required parameters and click on Connect.

The main code changes from V1.0 to V1.1

/// <summary>
    /// Used to execute queries
/// </summary>

/// <param name="dataBaseName">the name of the database</param>
/// <param name="query">the query string to execute</param>
private void ExecuteQuery(string dataBaseName , string query)
    DataTable dt;
    if (ds == null) 
        ds  = new DataSet("result");
    if (query.Trim() == "")

        dt = dbh.ExecDT(query);
        if (dt != null)
            ((frmQueryWriter)this.ActiveMdiChild).RenderGrid (dt);
    catch (Exception ex)

/// <summary> 
///   Creates dynamic grids in the output windows based on no. of 
///   queries
/// </summary>

/// <param name="dt">the datatable </param>

public void  RenderGrid(DataTable dt)
    if (buttonIndex == 0)   // 0 the query
        this.dgResult.DataSource = dt;      

    tabResult.Controls.Add(new TabPage("Result " 
        + buttonIndex.ToString()));

    tabResult.TabPages[tabResult.TabPages.Count-1].Name = 
        "tabPages"+ buttonIndex.ToString();

    CreateGridInTabControl(dt, "dgResult" + 


/// <summary>
/// This code actually creates the grid control in the output 
/// window
/// </summary>

/// <param name="dt">the datatable </param>
/// <param name="gridName">the grid name</param>

public void CreateGridInTabControl(System.Data.DataTable dt, string gridName)
    System.Windows.Forms.DataGrid dg = new System.Windows.Forms.DataGrid ();
    dg.Name = gridName;
    dg.DataSource = dt;
    dg.Top = dgResult.Top;
    dg.Left = dgResult.Left;
    dg.Anchor = dgResult.Anchor;
    dg.Dock = dgResult.Dock;
    dg.Width = dgResult.Width;
    dg.Height = dgResult.Height;

To connect to the database, the following code snippet is used:

/// <summary>
/// Connect to the datasource
/// </summary>
/// <param name="sender"></param>

/// <param name="e"></param>

private void btnConnect_Click(object sender, System.EventArgs e)
    this.Cursor = Cursors.WaitCursor;
    QASharp.DataBase db = new QASharp.DataBase();


          this.MdiParent).cmbDatabase, txtDatabase.Text);
    catch (Exception ex)
        MessageBox.Show("Error in connection. : " + ex.Message);
    this.Cursor = Cursors.Default;

To set the default database, the following code snippet is used:

public static void SetDefaultDatabase(ComboBox combo)
    string defaultDatabase;
    defaultDatabase = 
    combo.SelectedIndex = combo.FindString(defaultDatabase);

To display the error messages, the following code snippet is used:

private void ShowErrors()
    if (ErrorText.Trim() == "" ) 
        MessageBox.Show("No Errors.");

To save the existing query:

private void SaveFile()
    frmQueryWriter frmCurrentForm;
    frmCurrentForm = (frmQueryWriter)this.ActiveMdiChild;

    if (frmCurrentForm.Tag != null)
        if (frmCurrentForm.Tag.ToString().Trim() != "") 
        frmCurrentForm.Text = saveFD.FileName;


  • Efficient algorithm for syntax highlighting.
  • A treeview of the left panel showing the number of servers connected and the related database and tables.

Revision history

  • 1.0 - 12-23-2003 - Original article
  • 1.1 - 02-22-2004
    • Multiple query output window.
    • Syntax highlighting.
    • Connect to different data source menu option.


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


About the Author

Rajesh Pillai
India India
Co Founder at TekAcademy Labs.

You may also be interested in...


Comments and Discussions

Generalanother problem Pin
eckel30-Mar-04 19:13
membereckel30-Mar-04 19:13 
GeneralRe: another problem Pin
Rajesh Pillai30-Mar-04 19:59
memberRajesh Pillai30-Mar-04 19:59 
GeneralThere is a problem! Pin
eckel29-Mar-04 3:46
membereckel29-Mar-04 3:46 
GeneralRe: There is a problem! Pin
Rajesh Pillai30-Mar-04 18:06
memberRajesh Pillai30-Mar-04 18:06 
QuestionWhy not whole connection string? Pin
Dr Herbie22-Feb-04 1:35
memberDr Herbie22-Feb-04 1:35 
AnswerRe: Why not whole connection string? Pin
Rajesh Pillai22-Feb-04 18:08
memberRajesh Pillai22-Feb-04 18:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 22 Feb 2004
Article Copyright 2004 by Rajesh Pillai
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid