SqlConnection类中的默认网络协议是什么 [英] What is the default network protocol in SqlConnection class

查看:61
本文介绍了SqlConnection类中的默认网络协议是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In following code snippet, What will be the network protocol used to connect to the SQL Server? TCP/IP or Named Pipes or others?

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本机客户端

According to the 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.

,我们还阅读:

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

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,然后是命名管道-因此将不使用"a"协议-它取决于成功的内容.

So that is the order that they'll be attempted - TCP first, then Named Pipes - and so there's not "a" protocol that will be used - it depends on what succeeds.

这篇关于SqlConnection类中的默认网络协议是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆