码迷,mamicode.com
首页 > Web开发 > 详细

ado.net(1)

时间:2014-10-13 16:04:09      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:blog   io   使用   ar   数据   div   on   cti   log   

connection对象处于最顶层,是所有数据请求的关口

数据库连接过程

SqlConnection theConnection = new SqlConnection();
            //创建一个connection的对象实例
            theConnection.ConnectionString = "server=.;integrated security=true;";
            //设置其连接字符串,本地连接,集成安全连接
            //在连接字符串作为参数传给创建connection对象实例的代码前,最好将其赋给一个字符串
            //string connectionstring = "server=.;integrated security=true;";
            //SqlConnection theconnection=new SqlConnection(connectionstring);
            //在连接字符串作为参数传给创建connection"
            theConnection.Open();
            if (theConnection.State == System.Data.ConnectionState.Open)
                Console.WriteLine("database connection is open");

  sqlclient数据提供了另一种构造连接字符串的方法,即使用sqlconnectionstringbuilder对象

使用SqlConnectionStringBuilder的好处是,在输入无效的连接字符串时引发异常

三种方法来指定连接数据源的属性

1通过connection对象的connectionString属性指定连接字符串

2将连接字符串传入connection对象的构造函数中

3使用数据源配置向导

ado.net(1)

标签:blog   io   使用   ar   数据   div   on   cti   log   

原文地址:http://www.cnblogs.com/lj940306/p/4021995.html

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