引用命名空间
using System.Data;
using System.Data.SqlClient;
//1.连接
string connString = "Data Source=.;Database=db_BBS;Integrated Security=True;";
SqlConnection conn = new SqlConnection(connString);
try
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
}
catch (Exception ex)
{
throw;//来抛出发生异常的根本来源
}
finally
{
conn.Close();
}