این کد رو توی همین سایت پیدا کردم!!
private void Attach_db(string db_Name, string Path_Mdf, string Path_Ldf)
{
try
{
SqlConnection con = new SqlConnection("server=.;trusted_connection=yes;");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sp_attach_db @dbname = N'" + db_name + "', @filename1 = N'" + Path_Mdf + "', @filename2 = N'" + Path_Ldf + "'";
cmd.CommandType = CommandType.Text;
con.Open();
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e);
}
}