我有一个搜索按钮,可以通过在文本框中输入的名称搜索数据库,这在 Visual Studio 中运行良好,但是当尝试在托管版本中使用它时,我收到以下消息:
“/”应用程序中的服务器错误。
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)
这个按钮的代码是:
GridView2.Visible = True
lblEnterName.Text = ""
If txtLoanName.Text = "" Then
lblEnterName.Text = "Please enter a Bandie's Name"
Else
Dim conn As SqlConnection = Nothing
Try
Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BandDatabase.mdf;Integrated Security=True;User Instance=True"
conn = New SqlConnection(connString)
Dim query As String = "SELECT [SongName], [PartLearnt], [Status] FROM [Learning] WHERE ([BandieName] LIKE '%' + @Name + '%') ORDER BY [SongName]"
Dim cmd As SqlCommand = New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@Name", txtLoanName.Text)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
dt.Load(dr)
GridView2.DataSource = dt
GridView2.DataBind()
lblSearchBandieName.Text = "Progress for " + txtLoanName.Text
Finally
conn.Close()
End Try
End If
我不确定为什么这会带来以前没有的错误,我所做的只是更改了按钮所在的页面。
谢谢