ADO.NET连接数据库

时间:2014-05-09 04:01:32   收藏:0   阅读:388
bubuko.com,布布扣
bubuko.com,布布扣
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
 
protected void Page_Load(object sender, EventArgs e)
        {
             SqlConnection conn = new SqlConnection(@"server=HP\MYSQL;uid=sa;pwd=123456;database=Book_Management_System;timeout=10");        //无密码验证模式的ConnectString为(server=HP\\SQLEXPRESS;database=binguan;Integrated Security=SSPI;timeout=5)
            try
            {
                conn.Open();        //打开连接
            }
            catch (SqlException E)
            {
                (Master.FindControl("ErrorDisplay") as Label).Text = E.Message.ToString();        //将错误显示在ErrorDisplay这个Label控件中
            }
            finally
            {
                conn.Close();       //关闭数据库连接
            }
        }
bubuko.com,布布扣

 

bubuko.com,布布扣

 

ADO.NET连接数据库,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!