SqlConnection类中的默认网络协议是什么

Raj*_*ian 3 .net c# sql-server asp.net ado.net

在下面的代码片段中,用于连接SQL Server的网络协议是什么?TCP/IP或命名管道或其他?

using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
    //
    // First access the connection string.
    // ... This may be autogenerated in Visual Studio.
    //
    string connectionString = "Server=SERVER\\INSTANCE;Database=myDataBase;User Id=myUsername;
Password=myPassword;"
    //
    // In a using statement, acquire the SqlConnection as a resource.
    //
    using (SqlConnection con = new SqlConnection(connectionString))
    {
        //
        // Open the SqlConnection.
        //
        con.Open();
        //
        // The following code uses an SqlCommand based on the SqlConnection.
        //
        using (SqlCommand command = new SqlCommand("SELECT TOP 2 * FROM Dogs1", con))
        using (SqlDataReader reader = command.ExecuteReader())
        {
        while (reader.Read())
        {
            Console.WriteLine("{0} {1} {2}",
            reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
        }
        }
    }
    }
}
Run Code Online (Sandbox Code Playgroud)

Dam*_*ver 8

根据SQL Server Native Client 配置:

按列出的顺序尝试协议,尝试首先使用顶级协议进行连接,然后使用第二个列出的协议等进行连接.

但是,我们还读到:

Microsoft .NET SqlClient不使用这些设置..NET SqlClient的协议顺序是TCP,然后是命名管道,不能更改.

这就是他们将要尝试的顺序 - 首先是TCP,然后是命名管道 - 因此不会使用"a"协议 - 这取决于成功的原因.