Link to home
Create AccountLog in
Avatar of amruthanet
amruthanet

asked on

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
                        objAdapter.Fill(objDataSet)

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

                        objConnection.Close()
                        TxtLName.Enabled = False
                    Else
                        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

 
Avatar of naveenkohli
naveenkohli

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.
Avatar of amruthanet

ASKER

Thanks.  The port number is 2433.  How can I open the port?

Please let me know.
ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I found the problem. I have misspelled the datasource name.

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