标签:.net c# sql server 数据库
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace CSharpConnectSQL { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCSharpConnectSQL_Click(object sender, EventArgs e) { string strConnection = "Server=localhost;"; strConnection += "initial catalog=Northwind;"; strConnection += "user id=sa;"; strConnection += "password=123;"; strConnection += "Connect Timeout=5"; bool canConnectSQL = false; using (SqlConnection objConnection = new SqlConnection(strConnection)) { try { objConnection.Open(); canConnectSQL = true; objConnection.Close(); } catch { } if (canConnectSQL) MessageBox.Show("数据库连接成功!", "Crazygolf Alert"); else { MessageBox.Show("数据库连接失败!", "Crazygolf Alert"); } } } } }请注意以下几点:
标签:.net c# sql server 数据库
原文地址:http://blog.csdn.net/crazygolf/article/details/44725063