码迷,mamicode.com
首页 > 数据库 > 详细

C#基础——数据库连接

时间:2015-12-16 12:14:41      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

SQL Server Express数据库连接字符串: 

con.ConnectionString =@"Data Source=localhost\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=false;uid=sa;

pwd=password"

Initial Catalog:数据库名称。

Integrated Security:false表示使用SQL Server身份认证(sa,password),true表示使用Windows身份认证。 

示例: 

需要加一个Label控件 

完整实验代码:

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection();
            con.ConnectionString =@"Data Source=localhost\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=false; uid=sa;pwd=password"
            try{
                con.Open();
                Label1.Text="success";
                con.Close();
            }
            catch{
                Label1.Text="false";
            }

        } 

C#基础——数据库连接

标签:

原文地址:http://www.cnblogs.com/bluewhy/p/5050652.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!