建立与Server的连接时发生与网络相关或特定于实例的错误

时间:2015-10-30 04:33:02

标签: vb.net

我通常通过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和密码是正确的。什么似乎是问题?感谢

1 个答案:

答案 0 :(得分:0)

这可能是由于以下任何问题造成的。

1) Network issue
2) SQL Server configuration issue
3) Firewall issue
4) Client driver issue
5) Application configuration issue
6) Authentication and logon issue 

检查此方法的一些方法:

1. Check if your SQL has started: 
Start->Control Panel -> Administration Tools -> Services.
Find the firewall service here to see if it is disabled.
If not, right click the service and select Stop from the context menu.

2. Make sure your database engine is configured to accept remote connections:
a) Open SQL Server Management Studio. 
b) Right click SQL Server instance -> Properties -> Connections ->  Check the Allow remote connections to this server box. 
c) Go to the General section and check name of SQL Server specified in the Name field.