c# - SqlConnection 类中的默认网络协议(protocol)是什么

标签 c# asp.net .net sql-server ado.net

在下面的代码片段中,用于连接到 SQL Server 的网络协议(protocol)是什么? 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));
        }
        }
    }
    }
}

最佳答案

根据 SQL Server Native Client Configuration :

Protocols are tried in the order listed, attempting to connect using the top protocol first, and then the second listed protocol, etc.

但是,我们还读到:

These settings are not used by Microsoft .NET SqlClient. The protocol order for .NET SqlClient is first TCP, and then named pipes, which cannot be changed.

这就是他们将尝试的顺序 - 首先是 TCP,然后是命名管道 - 因此不会使用“一个”协议(protocol) - 这取决于成功。 p>

关于c# - SqlConnection 类中的默认网络协议(protocol)是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25541281/

相关文章:

c# - 从内容页面替换 css 文件

c# - 一个函数会打印多少次到控制台?

c# - 如果 SetForegroundWindow 和 ShowWindowAsync 不起作用,我该如何设置前景窗口?

c# - Entity Framework 异常 : Invalid object name

c# - 在洋葱架构中放置 View 模型/DTO

c# - 返回受 SQL UPDATE 语句影响的行

asp.net - DNN 中不同用户的自定义界面..如何?

c# - 由于泛型类型推断的限制,无法使用泛型来改进 API

c# - 在实现自己的 IUserStore 时,类上的 "optional"接口(interface)实际上是可选的吗?

c# - C#asp.net中UPDATE语句中的语法错误