Translate to ASP.NET v2, please

Posted on 2006-03-27
Last Modified: 2013-11-25
Hello - I found a promising code sample for adding search capability to an ASP.NET website: "How to use an ASP.NET application to query an Indexing Service catalog by using Visual Basic .NET" (;en-us;820105#kb1 )

It's in ASP.NET v1; I caught all the easy things, and made all the changes suggested by the debugger, but it's still getting an error down on the line:   cmd.Fill(testDataSet)

I'm new to ASP.NET alltogether, much less v1 vs v2; I would appreciate it if somebody could translate this to v2

Here's the HTML:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="IndexQueryApp.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
            <title>Query an Indexing Service Catalog</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
            <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="">
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 238px; POSITION: absolute; TOP: 76px" runat="server"></asp:TextBox>
                  <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 153px; POSITION: absolute; TOP: 127px"
                        runat="server" AutoGenerateColumns="False">
                              <asp:BoundColumn DataField="DocTitle" HeaderText="DocTitle"></asp:BoundColumn>
                              <asp:BoundColumn DataField="filename" HeaderText="FileName"></asp:BoundColumn>
                              <asp:BoundColumn DataField="size" HeaderText="Size"></asp:BoundColumn>
                              <asp:BoundColumn DataField="path" HeaderText="PATH"></asp:BoundColumn>
                              <asp:BoundColumn DataField="url" HeaderText="URL "></asp:BoundColumn>
                  <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 638px; POSITION: absolute; TOP: 145px" runat="server"

Here's the code:

Public Class WebForm1
   Inherits System.Web.UI.Page
   Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
   Protected WithEvents Button1 As System.Web.UI.WebControls.Button
   Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
   Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

   'Web Form Designer requires this call.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
      Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection()

   End Sub

   Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
      'CODEGEN: Web Form Designer requires this method call.
      'Do not modify it by using the code editor.
   End Sub

#End Region

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim strCatalog As String

      ' Catalog Name
      strCatalog = "TestCatalog"

      Dim strQuery As String
      strQuery = "Select DocTitle,Filename,Size,PATH,URL from SCOPE() where FREETEXT('" & TextBox1.Text & "')"
      ' TextBox1.Text is word that you type in the text box to query by using Index Service.
      Dim connString As String = "Provider=MSIDXS.1;Integrated Security .='';Data Source='" & strCatalog & "'"

      Dim cn As New System.Data.OleDb.OleDbConnection(connString)
      Dim cmd As New System.Data.OleDb.OleDbDataAdapter(strQuery, cn)
      Dim testDataSet As New DataSet()


      ' Bind DataGrid to the DataSet. DataGrid is the ID for the
      ' DataGrid control in the HTML section.
      Dim source As New DataView(testDataSet.Tables(0))
      DataGrid1.DataSource = source
   End Sub
End Class



Question by:mlagrange
    LVL 39

    Expert Comment


    whats the error?
    LVL 3

    Expert Comment

    from what i know, lol, asp vs 2.0 is backwards compatible with 1.1 and 1.0 applications

    Author Comment

    When I enter a value in the text box and click the "Button", it eventually comes up in the debugger on the line with:
    with the messages:
          "OleDbException was unhandled by user code", "Service is not running"

    As far as backward compatibility, I don't think there is any, at least within Visual Web Developer (which I am using). At one point, I was getting a message along the lines of "{no longer supported... open the project in Visual Web Developer}"  

    I made the following changes to the HTML:
    > There were evidently no Master/Content pages in v1; I brought in the controls between the <form> tags in to a new content page (still named "WebForm1"), and left everything else (<meta> spec's, "MS_POSITIONING", etc.) out.
    > Changed "CodeBehind" to "CodeFile"  
    > Removed all the "style="Z-INDEX: " spec's

    In the code, I followed the recommendations from the debugger (or else took a chance):
    > Removed all the "Protected WithEvents" except for the one for "OleDbConnection1"
    > Removed the #Region section
    > Removed the Page_Load sub (nothing in it)
    > Changed "Dim testDataSet As New DataSet()" to "Dim testDataSet As New Data.DataSet()"
    > Changed "Dim source As New DataView(testDataSet.Tables(0))" to "Dim source As New Data.DataView(testDataSet.Tables(0))"

    I know even less about VB.NET than I do ASP.NET, at this point; hopefully, the problem is something simple/syntactical on that line "cmd.Fill(testDataSet)"

    Thanks in advance for your help


    LVL 39

    Accepted Solution

    >>"OleDbException was unhandled by user code", "Service is not running"
    this means you have not started the indexing service.

    from;en-us;820105#kb1  (same link from your question)
    do the following

    Create a test folder
    1. Create a new folder on the C drive of your computer. Name the folder myCatalogFolder.
    2. Start Notepad, and then paste the following text in a blank document:
    This is test document to test the index server query and this file name is IndexText.text.
    3. Save the file as C:\myCatalogFolder\IndexText.txt.

     Back to the top

    Create an Indexing Service catalog
    1. Click Start, and then click Control Panel.
    2. Double-click Administrative Tools.
    3. Click Computer management.
    4. Expand Services and Applications.
    5. Right-click Indexing Service, point to New, and then click Catalog.  
    6. In the Name text box, type TestCatalog.
    7. Click Browse, locate the folder where you want to put the catalog, and then click OK two times.
    8. Following message appears under New Catalog Created:
    Catalog will remain off-line until Indexing Service is restarted
    Click OK.
    9. Right-click Indexing Service, and then click Stop to stop the Indexing Service.
    10. Right-click Indexing Service, and then click Start to restart the Indexing Service.

     Back to the top

    Define the scope of the catalog
    After you create a new catalog, add the folders that you want included in the scope of the catalog. The scope is the set of folders that is included in and excluded from the catalog. The scope defines the content that is included and excluded from the index. For each folder that is included or excluded, all its subfolders are also included or excluded. 1. Double-click TestCatalog (the catalog that you created in the "Create a Test Folder" section).
    2. Right-click Directories, point to New, and then click Directory.
    3. Click Browse, locate and then click the folder that you want to add (C:\myCatalogFolder\), and then click OK.

    Note Under Include in Index ?, click Yes.

    Author Comment

    Argh! It dawned on me what the problem is/was, about the same instant I got your reply.

    Then, FWIW, I realized I needed to change strCatalog to be the actual catalog name

    It's working now...

    Thank you


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now