• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Searchable form in vb.net /getting an error while accessing the database- Urgent please help

Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
        Dim dr As SqlClient.SqlDataReader
        Dim objConnection As New SqlClient.SqlConnection
        Dim objCommand As New SqlClient.SqlCommand
        Dim objAdapter As New SqlClient.SqlDataAdapter
        Dim objDataSet As New DataSet
        Dim strSearch As String
        Dim strSQLQuery As String
        ' Get Search
        If Page.IsValid Then
            strSearch = txtFname.Text
                    ' If there's nothing to search for then don't search
                    ' o/w build our SQL Query and execute it.
                    If Len(Trim(strSearch)) > 0 Then
                        ' Set up our connection.
                objConnection = New SqlClient.SqlConnection("Data Source=daisql;" _
                         & "Initial Catalog=KSBOA_DATA;User Id=guest000;Password=guest000;")

                        ' Set up our SQL query text.
                        strSQLQuery = "SELECT firstname,lastname, city, state " _
                         & "FROM tblboadata " _
                         & "WHERE lastname LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
                        & "OR firstname LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
                         & "ORDER BY lastname;"

                        ' Create new command object passing it our SQL query
                        ' and telling it which connection to use.
                        objCommand = New SqlClient.SqlCommand(strSQLQuery, objConnection)

                        ' Get a DataSet to bind the DataGrid to
                        objAdapter = New SqlClient.SqlDataAdapter(objCommand)
                        objDataSet = New DataSet

                        ' DataBind DG to DS
                        dgIndividual.DataSource = objDataSet.DefaultViewManager

                        TxtLName.Enabled = False
                        txtFname.Text = "Enter Search Here"
                    End If
        End If
    End Sub

Error received:

Line 90:                         objAdapter = New SqlClient.SqlDataAdapter(objCommand)
Line 91:                         objDataSet = New DataSet
Line 92:                         objAdapter.Fill(objDataSet)
Line 93:
Line 94:                         ' DataBind DG to DS

Source File: c:\inetpub\wwwroot\BOASearch\Search for Individual.aspx.vb    Line: 92

Stack Trace:

[SqlException: SQL Server does not exist or access denied.]
   System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474
   System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
   System.Data.SqlClient.SqlConnection.Open() +384
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
   System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
   BOASearch.IndividualSearch.btnsearch_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\BOASearch\Search for Individual.aspx.vb:92
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292

  • 3
  • 2
1 Solution
Do you have a firewall on the server? Check if port 1433 is bieng blocked by it. If it is, then you need to open that port to allow access to SQL server.
amruthanetAuthor Commented:
Thanks.  The port number is 2433.  How can I open the port?

Please let me know.
What kind of firewall is it? Is it the one that comes with XP - SP2?
amruthanetAuthor Commented:
I found the problem. I have misspelled the datasource name.

Thanks for your help.
Post a comment in admin area to delete this question.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now