【问题标题】:A network-related or instance-specific error occurred while establishing a connection to Server与服务器建立连接时发生与网络相关或特定于实例的错误
【发布时间】: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


    【解决方案1】:

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

    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.
    

    【讨论】:

    • 嗨,它实际上在服务器上,我无法访问。我可以使用相同的凭据通过 ODBC 连接到服务器。还有什么我可以尝试的吗?谢谢
    • 检查是否有帮助:technologycrowds.com/2014/02/…
    • 嗨,我的机器上什至没有 Microsoft SQL Server 2008 R2。我应该安装它吗?顺便说一句,ODBC 不是也远程连接吗?谢谢
    • 你在使用那个数据库吗?那么当它甚至不在您的机器中时,您如何尝试连接它?
    • 脚本上传到共享服务器。我没有尝试连接到 localhost。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多