using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;
namespace Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String serv = "Data Source=.;Initial Catalog=Emp;Integrated Security=True;";
SqlConnection conn = new SqlConnection(serv);
try
{
conn.Open();
MessageBox.Show("连接成功");
}
catch (Exception ex)
{
MessageBox.Show("连接失败" + ex.Message);
}
finally {
if (conn != null) {
conn.Close();
}
}
}
}
}
|