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("D ata Source=daisql;" _
& "Initial Catalog=KSBOA_DATA;User Id=guest000;Password=guest 000;")
' 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(strSQ LQuery, objConnection)
' Get a DataSet to bind the DataGrid to
objAdapter = New SqlClient.SqlDataAdapter(o bjCommand)
objDataSet = New DataSet
objAdapter.Fill(objDataSet )
' DataBind DG to DS
dgIndividual.DataSource = objDataSet.DefaultViewMana ger
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(o bjCommand)
Line 91: objDataSet = New DataSet
Line 92: objAdapter.Fill(objDataSet )
Line 93:
Line 94: ' DataBind DG to DS
Source File: c:\inetpub\wwwroot\BOASear ch\Search for Individual.aspx.vb Line: 92
Stack Trace:
[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.Conn ectionPool .GetConnec tion(Boole an& isInTransaction) +474
System.Data.SqlClient.SqlC onnectionP oolManager .GetPooled Connection (SqlConnec tionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlC onnection. Open() +384
System.Data.Common.DbDataA dapter.Qui etOpen(IDb Connection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataA dapter.Fil lFromComma nd(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet) +38
BOASearch.IndividualSearch .btnsearch _Click(Obj ect sender, EventArgs e) in c:\inetpub\wwwroot\BOASear ch\Search for Individual.aspx.vb:92
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +108
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +57
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +33
System.Web.UI.Page.Process RequestMai n() +1292
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("D
& "Initial Catalog=KSBOA_DATA;User Id=guest000;Password=guest
' 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(strSQ
' Get a DataSet to bind the DataGrid to
objAdapter = New SqlClient.SqlDataAdapter(o
objDataSet = New DataSet
objAdapter.Fill(objDataSet
' DataBind DG to DS
dgIndividual.DataSource = objDataSet.DefaultViewMana
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(o
Line 91: objDataSet = New DataSet
Line 92: objAdapter.Fill(objDataSet
Line 93:
Line 94: ' DataBind DG to DS
Source File: c:\inetpub\wwwroot\BOASear
Stack Trace:
[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.Conn
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
System.Data.Common.DbDataA
System.Data.Common.DbDataA
System.Data.Common.DbDataA
System.Data.Common.DbDataA
BOASearch.IndividualSearch
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
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.
ASKER
Thanks. The port number is 2433. How can I open the port?
Please let me know.
Please let me know.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I found the problem. I have misspelled the datasource name.
Thanks for your help.
Thanks for your help.
Cool..
Post a comment in admin area to delete this question.
Post a comment in admin area to delete this question.