在以下代碼片段中,將用於連接到SQL Server的網絡協議是什麼? TCP/IP或命名管道或其他?什麼是SqlConnection類中的默認網絡協議
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));
}
}
}
}
}
所以默認的端口號是1433,協議是TCP/IP? – 2014-08-28 05:31:32
@RajeshSubramanian - 它會*嘗試*先使用TCP,但可能會回退到命名管道。 – 2014-08-28 05:32:24