本文介绍了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:

,我们还阅读:

这就是尝试它们的顺序-首先是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类中的默认网络协议是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:27