Active Query Builder support area

[Obsolete] Getting started with AQB 2 ASP.NET Edition in WebForms (non-MVC) project

Last modified:


Important:

This guide is only for the WebForms (non-MVC) ASP.NET environment!

Please refer to the appropriate guides for MVC environments:

Follow the steps below to install Active Query Builder ASP.NET Edition to your project. 

Easy installation
by using the NuGet package:
Traditional installation
by following the steps of this guide:
  1. Add the NuGet Package Manager Visual Studio extension.
  2. Add the "Active Query Builder 2 ASP.NET Edition" NuGet package to your project.
  3. Add typical HTML code and the component's initialization code to your web page.
  1. Add the necessary assemblies.
  2. Add the necessary HTTP handlers and modules according to your IIS version.
  3. Add the necessary JavaScript and CSS files.
  4. Load JavaScript libraries manually or using the Script Manager.
  5. Add typical HTML code and the component's initialization code to your web page.

 

  1. Create a new solution and add a new project – ASP.NET Web Application.
    The steps below can be skipped in case of using the "Active Query Builder 2 ASP.NET Edition" NuGet package. Proceed to the final steps in the case of using it.

     

  2. Add references to the following assemblies:
    • \assemblies\.NET 2.0\ActiveDatabaseSoftware.ActiveQueryBuilder2.dll
    • \assemblies\.NET 2.0\ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Control.dll
    • \assemblies\.NET 2.0\ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Server.dll
    • \assemblies\third-party\Newtonsoft.Json.dll
    • \assemblies\third-party\log4net.dll
    You may also need to add the assemblies for specific metadata providers to retrieve metadata from a database, e.g.:
    • \assemblies\.NET 2.0\ActiveDatabaseSoftware.OLEDBMetadataProvider.dll
    Is it necessary to set the CopyLocal property of "ActiveDatabaseSoftware.ActiveQueryBuilder2.*" assemblies to True. This isn't done automatically in case of instructing to install the component to the Toolbox because assemblies are installed to GAC in this case.
    Active Query Builder requires Newtonsoft Json assembly version not earlier than 4.5. Apache log4net.dll is required only in debug configuration. Active Query Builder is bound to the log4net binary version labelled as "oldkey" for compatibility with earlier versions of this library.

     

  3. Add the necessary HTTP handlers and modules to the "web.config" file according to your web server version.
    • For IIS 6, add the following handlers in the "configuration/system.web/httpHandlers" section:
         <add path="handlers/exchange.axd" verb="*" 
            type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.Exchange,
            ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Server"
         />
      and the following module to the "configuration/system.web/httpModules" section:
         <add name="HttpModule" 
            type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.HttpModule,
            ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Server"
         />
    • For IIS 7 and higher, add the following handlers in the "configuration/system.webServer/handlers" section:
         <add name="handlers/exchange.axd_*" preCondition="integratedMode"  
            path="handlers/exchange.axd" verb="*" 
            type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.Exchange,
            ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Server" 
         />
      and the following module to the "configuration/system.webServer/modules" section:
         <add name="HttpModule" preCondition="integratedMode"
            type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.HttpModule,
            ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Server" />

    Additionally, you can define the HttpCompressionEnabled and MultipleQueriesPerSession options in the 'web.config' file as follows:

    <appSettings>
    <add key="HttpCompressionEnabled" value="false" />
    <add key="MultipleQueriesPerSession" value="false" />
    </appSettings>

    Targeting the project for .NET Framework 4.5, you must set the HttpCompressionEnabled option to False (this is the default value). You can turn on HTTP compression by the means of IIS as described here.

     

  4. Get content from the "web_parts" directory ("css", "img" and "js" sub-folders) and put it in the directory of the web page or the parent control. Alternatively, you can set paths to specific locations of these directories using the QueryBuilderControl.DirectoryJS and the QueryBuilderControl.DirectoryCSS properties. The necessary JavaScript libraries are loaded automatically unless a different behaviour is not determined by the QueryBuilderControl. LoadJScript property. Setting this property to false might be needed in case of using the Script Manager or some other dynamic JavaScript loading tool. To load the necessary libraries using Script Manager having set the LoadJScript to false, usе this code:
    <asp:ScriptManager runat="server">
       <Scripts>
          <asp:ScriptReference Name="jquery" />
          <asp:ScriptReference Name="jquery.ui.combined" />
          <asp:ScriptReference Path="~/js/release/usr_v0_x_x.js" />
    To load the necessary libraries manually having set the LoadJScript to false, add the following code to the HEAD section of your web page:
    <script src="js/release/jquery.js" type="text/javascript"></script>
    <script src="js/release/jquery-ui.js" type="text/javascript"></script>
    <script src="js/release/usr_v0_x_x.js" type="text/javascript"></script>
    • Active Query Builder ASP.NET Edition requires jQuery 1.11 or higher, and jQueryUI 1.10.4 or higher; latest versions of the 2.x branch are recommended.
    • The default CSS theme allows for flex layout of controls but limits support of web browsers (details). To get Active Query Builder compatible with legacy web browsers (IE 8-9), use the old CSS files contained the "web_parts\legacy_css" folder.

     

  5. Typical HTML code can be found in the "web_parts\!(C# or VB)" folder, in "Default.aspx" and "QueryBuilder.ascx" files, or you can simply add the following content to your web-page.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Client.Default" %>
    <%@ Register Assembly="ActiveDatabaseSoftware.ActiveQueryBuilder2.Web.Control" Namespace="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Control" TagPrefix="AQB" %>
    <html>
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="Form1" runat="server">
    
        <AQB:QueryBuilderControl ID="QueryBuilderControl1" runat="server" OnInit="QueryBuilderControl1_Init" />
        <div id="all">
            <div id="content-container">
                <div id="qb-ui">
                    <AQB:ObjectTreeView ID="ObjectTree1" runat="server" />
                    <div id="center">
                        <AQB:SubQueryNavigationBar ID="SubQueryNavigationBar1" runat="server" />
                        <div class="qb-ui-canvas-container block-flat">
                            <AQB:Canvas ID="Canvas1" runat="server" />
                            <AQB:StatusBar ID="StatusBar1" runat="server" />
                            <AQB:Grid ID="Grid1" runat="server" />
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
            <AQB:SqlEditor ID="SQLEditor1" runat="server"></AQB:SqlEditor>
        </div>
    
            </form>
        </body>
    </html>

     

  6. Place your initialization code in the QueryBuilderControl.Init event handler. There you should create Metadata and Syntax provider components and link these providers to the QueryBuilder object by setting the MetadataProvider and SyntaxProvider properties. Define a proper database connection object as a source for the Metadata provider or load metadata from the XML file. The server side of the component is based on the WinForms .NET Edition of Active Query Builder. There are two object references available to get access to their methods and properties: QueryBuilderControl.QueryBuilder and QueryBuilderControl.PlainTextSQLBuilder.
    private void QueryBuilderControl1_OnInit(object sender, EventArgs e)
    {
        // Get instance of the QueryBuilder object
        QueryBuilder queryBuilder = QueryBuilderControl1.QueryBuilder;
    
        // Create an instance of the proper syntax provider for your database server. 
        // - use AutoSyntaxProvider if you want to detect your database server automatically 
        //   (autodetection works in case of live database connection only);
        // - use ANSI or Generic syntax provider only if you can't find the right syntax 
        //   provider for your database server.
    
        MSSQLSyntaxProvider syntaxProvider = new MSSQLSyntaxProvider(); 
        queryBuilder.SyntaxProvider = syntaxProvider;
    
        // Metadata source definition: Choose a) or b):
        // 
        // a) you can load metadata from live database connection
    
        OleDbConnection connection = new OleDbConnection {ConnectionString = "<your connection string here>"};
        queryBuilder.MetadataProvider = new OLEDBMetadataProvider {Connection = connection};
    
        // b) or you can load metadata from the pre-generated XML file
    
        // Deny metadata loading requests from the metadata provider
        queryBuilder.OfflineMode = true;
    
        sting pathToXml = Server.MapPath("~\Path\to\file.xml");
        queryBuilder.MetadataContainer.ImportFromXML(pathToXml);
    
        // end of b) 
    
        // Initialization of the Metadata Structure object that's
        // responsible for representation of metadata in a tree-like form
        try
        {
            // Clear and load the first level of the metadata structure tree  
            queryBuilder.MetadataStructure.Refresh();
        }
        catch (Exception ex)
        {
            Logger.Error("Error loading metadata.", ex);
        }
    }

     

  7. That's all! Now you can run your application.

What to read next?


Is this article helpful for you?