首页 > 数据库技术 > 详细

C#基础——数据库连接

时间:2015-12-16 12:12:40      阅读:265      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!