gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:37:08 29 4
gpt4 key购买 nike

在下面的代码片段中,用于连接到 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com