ADO. NET
Connect to SQL Server
The SQL Server. NET Framework Data Provider supports connection string formats similar to OLE DB (ADO) connection string formats.
Copy codeThe Code is as follows:
Using (SqlConnection connection = new SqlConnection (connectionString ))
{
Connection. Open ();
// Do work here.
}
Connect to the ole db Data Source
Ole db. NET Framework data providers provide connections to data sources exposed by ole db through OleDbConnection objects and to Microsoft SQL Server 6.x or earlier versions (through the ole db provider for SQL Server (SQLOLEDB)).
Copy codeThe Code is as follows:
Using (OleDbConnection connection = new OleDbConnection (connectionString ))
{
Connection. Open ();
// Do work here.
}
Connect to the ODBC Data Source
The ODBC. NET Framework data provider uses the OdbcConnection object to provide connections to data sources exposed by ODBC.
Copy codeThe Code is as follows:
Using (OdbcConnection connection = new OdbcConnection (connectionString ))
{
Connection. Open ();
// Do work here.
}
Connect to the Oracle Data Source
The Oracle. NET Framework data provider uses the OracleConnection object to provide a connection to the Oracle data source.
Copy codeThe Code is as follows:
Using (OracleConnection connection = new OracleConnection (connectionString ))
{
Connection. Open ();
// Do work here.
}
OracleConnection nwindConn = new OracleConnection ("Data Source = MyOracleServer; Integrated Security = yes ;");
NwindConn. Open ();
The following are the connection instances:
ACCESS
Copy codeThe Code is as follows:
StringconStr = @ "provider = microsoft. Jet. OleDb.4.0; datasource = d: \ accessData. mdb; uid = sa; pwd = dd ";
SQL SERVER
Copy codeThe Code is as follows:
StringconStr = @ "Server = bwj; database = demo; uid = sa; pwd = ";
ORACLE
Copy codeThe Code is as follows:
StringconStr = @ "Provider = MSDAORA.1; Password = pwd; UserID = user_name; Data Source = link_str"