Databases Reference
In-Depth Information
DataSet
Connection
The Connection object is used to connect to a database and control the
transactions in ADO.NET. Each data provider has different Connection Objects.
Each of the three data providers IBM DB2 incorporates has its own Connection
Objects (DB2Connection, OleDbConnection, and OdbcConnection).
The data connection class enables you to specify the connection string used to
connect to the target database server:
This is implemented as DB2Connection object in DB2 .NET Data Provider, for
example:
DB2Connection connection = new DB2Connection(“Database=SAMPLE”);
This is implemented as OleDbConnection object in DB2 OLE DB Data
Provider, for example:
OleDbConnection connection = new
OleDbConnection(“Provider=IBMDADB2.1;DSN=SAMPLE”);
This is implemented as OdbcConnection object in DB2 ODBC Data Provider,
for example:
OdbcConnection connection = new OdbcConnection(“DSN=SAMPLE”);
The connection object has public property ConnectionString , which is required
for establishing connection with a database. It requires database name and other
parameters such as user ID and password, for example:
connection.ConnectString = “Database=Sample”;
However, ConnectionString property can be set through passing the string to the
Connection Object Constructor as shown in following example:
DB2Connection connection = new DB2Connection( “Database=SAMPLE” ) ;
Connection objects have the following public methods:
Open : This opens a database connection as specified in a ConnectionString,
for example:
connection.Open();
Connections can be opened by explicitly calling the Open method on the
connection as shown above or by implicitly using a DataAdapter.
Close : This closes the database connection, for example:
connection.Close();
Search WWH ::




Custom Search