using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DBConnections
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
//Data Source就是打开sql时出现的服务器名称
string conStr = "Data Source=PZUM51D4ZOEY9QN;Initial Catalog=master;Persist Security Info=True;User ID=sa;pwd=sql";
SqlConnection con = new SqlConnection(conStr);
con.Open();
if (con.State == ConnectionState.Open)
{
MessageBox.Show("数据库连接成功");
}
}
catch
{
MessageBox.Show("数据库连接失败");
}
}
}
}