Pregunta

I am using vs 2012 Professional and SQL-Server 2012 Express.

I was trying to run Admin.aspx, that has a textbox to search for users in a db.

However, each time I try to search for a username I get this error

Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'users' because it is not full-text indexed.

From what I search Full-Text indexing needs to be enabled, for which in my case, it is greyed out in the SQL Server Management Studio and not available (???) in the Express edition.

How can I over come this problem?

Admin.aspx

Imports System.Data.SqlClient

Partial Class Admin
    Inherits System.Web.UI.Page

    Protected Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click

        Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
        Dim searchComm As String = "SELECT username FROM users WHERE CONTAINS (username, @username)"

        Dim searchSQL As New SqlCommand

        conn.Open()

        searchSQL = New SqlCommand(searchComm, conn)
        searchSQL.Parameters.AddWithValue("@username", txtUserSearch.Text)

        Dim datareader As SqlDataReader = searchSQL.ExecuteReader()

        While datareader.Read

            lstUsers.Items.Add(datareader.Item("username"))

        End While



        datareader.Close()
        conn.Close()

    End Sub
End Class

As you can see, the user enters a username in the searchbox, and for each record that contains words from the textbox input is added as an item in the listbox.

¿Fue útil?

Solución

I'm not convinced you need full-text search to check for equality in a username. Do you think you could use the following instead of CONTAINS?

SELECT username FROM dbo.users WHERE username = @username;

If you absolutely feel you need full-text search, then:

  1. You need Express Edition with Advanced Services; I don't think Visual Studio ships with that edition. You can download that here (SQLEXPRADV_x64_ENU.exe).
  2. You'll need to use DDL to create your full-text catalog and indexes, as I point out in this answer, as there are bugs in the UI that still seem to have gone unresolved. If you download (1) you'll have a version of Management Studio Express that might have fixes but will certainly be fully functional (the SP1 release was the first version of SSMS Express that has all the functionality of the full version, which may explains why it is greyed out).

Example:

CREATE FULLTEXT CATALOG my_catalog;
GO
CREATE FULLTEXT INDEX 
  ON dbo.users(username LANGUAGE 1033) 
  KEY INDEX uq_un ON my_catalog;

Otros consejos

Full text indexing requires at least SQL Server Express With Advanced Services, the standard Express edition doesn't have the capability of full text indexing.

Then you can create your full text catalogs and indexes, see the following link for more information:

Create and Manage Full-Text Indexes

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top