为什么总是与数据库连接不成功??请帮助一下,谢谢
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient ;
namespace connection对象
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请输入要连接的数据库的名称");
}
else
{
try
{
string strConn = " Data Source =(local);";//本地的数据库
strConn += textBox1.Text.Trim();
strConn += "integrated security=true;";//windows身份验证
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
if (conn.State == ConnectionState.Open)
{
label2.Text = "数据库【" + textBox1.Text.Trim() + "】已经连接并打开";
}
}
catch
{
MessageBox.Show("连接数据库失败");
}
}
}
}
}