【发布时间】:2015-10-30 12:40:28
【问题描述】:
我通常通过 odbc 连接到 MySQL,但在这种特殊情况下,我需要通过 sqlconnection 连接并将其绑定到下拉列表。这是我的脚本
Using con As New SqlConnection("Data Source=101.99.69.30; Database=recon; User ID=recon; PASSWORD=recon123;")
Using cmd As New SqlCommand("SELECT fid, fmake, fmodel FROM treconcalculation")
cmd.CommandType = CommandType.Text
cmd.Connection = con
Using sda As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
sda.Fill(ds)
vehicle1.DataSource = ds.Tables(0)
vehicle1.DataTextField = "fmodel"
vehicle1.DataValueField = "fid"
vehicle1.DataBind()
End Using
End Using
End Using
vehicle1.Items.Insert(0, New ListItem("--Select Customer--", "0"))
问题是,它在第 19 行给了我这个错误。
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
Line 17: Using sda As New SqlDataAdapter(cmd)
Line 18: Dim ds As New DataSet()
Line 19: sda.Fill(ds)
Line 20: vehicle1.DataSource = ds.Tables(0)
Line 21: vehicle1.DataTextField = "fmodel"
我已经确认了我通常使用的 odbc 字符串,并且来源、数据库、用户 ID 和密码是正确的。似乎是什么问题?谢谢
【问题讨论】:
标签: vb.net