【发布时间】:2014-10-21 20:55:41
【问题描述】:
在下面的代码 sn-p 中,用于连接 SQL Server 的网络协议是什么? 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));
}
}
}
}
}
【问题讨论】:
标签: c# asp.net .net sql-server ado.net