1. Trang chủ
  2. » Giáo án - Bài giảng

Lesson 1 ADO.NET

44 318 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 44
Dung lượng 818,78 KB

Nội dung

Chapter 2 Access data in a connected environment Lesson 1: ADO.NET Source: http://msdn.microsoft.com  Introduction  ADO.NET Components  Working in connected and disconnected environment  Connection objects  Command objects Contents Slide 2  ADO.NET is a set of classes that allows .NET Framework programmers to interact with data sources  The data source is a database (such as Microsoft SQL Server, Microsoft Access, Oracle, ), but it could also be a text file, an Excel spreadsheet, or an XML file  The System.Data namespace contains the core data access classes in the .NET Framework  The design goals of ADO.NET:  Leverage current ActiveX Data Objects (ADO) knowledge  Support the n-tier programming model  Integrate XML support Introduction to ADO.NET Slide 3  The two main components of ADO.NET for accessing and manipulating data:  The .NET Framework Data Providers  There isn't a single set of classes that allow you to interact with different types of data sources and different types of databases  A way to communicate with the right data source using the right protocol  Different sets of libraries for each way you can talk to a data source are called Data Providers  The DataSet  See next chapter ADO.NET Components Slide 5 ADO.NET Components (cont.) Slide 6 ADO.NET architecture Data Provider Description Namespace Data Provider for SQL Server Provides data access for Microsoft SQL Server version 7.0 or later. System.Data.SqlClient Data Provider for OLE DB For data sources exposed by using OLE DB, i.e. Access or Excel. System.Data.OleDb Data Provider for ODBC For data sources exposed by using ODBC. System.Data.Odbc Data Provider for Oracle For Oracle data sources, supports Oracle version 8.1.7 and later. System.Data.OracleClient EntityClient Provider Provides data access for Entity Data Model (EDM) applications. System.Data.EntityClient ADO.NET Components The .NET Framework Data Providers Slide 7  Core objects of .NET Framework Data Providers ADO.NET Components The .NET Framework Data Providers (cont.) Slide 8 Object Description Connection Establishes a connection to a specific data source. The connection helps identify the database server, the database name, user name, password, and other parameters Command Executes a command against a data source: get data, modify data, run stored procedures, and send or retrieve parameter information. DataReader Reads a forward-only, read-only stream of data from a data source. DataAdapter Populates a DataSet and resolves updates with the data source: the bridge between the DataSet object and the data source.  Each data provider provides an implementation of the Connection, Command, DataAdapter, and DataReader objects ADO.NET Components The .NET Framework Data Providers (cont.) Slide 9  Connected data access through the DataReader objects of data provider. This object provides forward-only, read-only access to data in the data source  Disconnected data access is achieved through the DataAdapter object. This object loads data in the DataSet that works independent of database and can edit the data Connected and disconnected data access Slide 10 DataReader Database Windows Form DataSet DataAdapter Disconnected Connected  What is a Connection object?  Creating and configuring Connection objects  Working with Connection pools  Handling Connection errors  Enumerating the available SQL Servers  Securing sensitive Connection string data Connection objects Slide 11 [...]... "Provider=Microsoft.ACE.OLEDB .12 .0; Data Source = QLSV.accdb"; conn.Open(); 16 Connection String Description Parameter Name Identifies the server Could be local Data Source machine, machine domain name, or IP Address Initial Catalog Database name Integrated Security Set to SSPI to make connection with user's Windows login User ID Name of user configured in SQL Server Password Password matching SQL Server User ID Slide 17 What... Each time call Open method with a unique connection string, a new pool is created 18 Controlling Connection pooling options   By default, connection pooling is enabled when creating ADO.NET connection (Pooling = True) Control connection pooling behavior by setting connection string    Pooling Min Pool Size Max Pool Size 19 Configuring Connections to Use Connection Pooling  Configuring Connection... identify the database server, the database name, user name, password, and other parameters 12 How to create Connection?  Creating Connections in Server Explorer   Creating Connections Using Data Wizards   P206 P207 Creating Connection Objects Programmatically  SQL Server   SQL / Integrated Security MS Access 13 Connection properties Name Description Get or set the string used to open the ConnectionString... Read only Get a string that describes the state of the connection 14 Connection methods Name Description Open Open a database connection with the settings specified by the ConnectionString You cannot open the connection that is opened Close Close the connection to the database This is the preferred method of closing any open connection 15 Open connection  Open the connection with database Northwind:... Security=True;Min Pool Size=5 Configuring Connection Pooling with OLE DB Connections   Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DatabaseName.mdb;OLE DB Services= -1 (See page 228-229) 20 Handling Connection Errors  NET Exceptions 21 Handling Connection Errors  OleDbException class exposes properties that contain details of the exception condition These include:     A Message property that... System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance; dataGridView1.DataSource = instance.GetDataSources(); 24 Enumerating the Available SQL  Why no SQL Servers appear?    Network traffic Firewall Service SQL Browser need to run 25 26 Securing Sensitive Connection String Data (p 2 41)  Protect your application   Secure information such as user IDs, data source names, passwords,…...  Windows Authentication (Integrated Security) 27 Securing Sensitive Connection String Data (p 2 41)  The suggested method of implementing security in applications (cont.)   Using the application configuration file (app.config) Add\Add new item, select 'Application Configuration file'

Ngày đăng: 13/05/2014, 12:18

Xem thêm

TỪ KHÓA LIÊN QUAN

w