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:
ACCESSCopy codeThe Code is as follows: stringconStr = @ "provider = microsoft. Jet. OleDb.4.0; datasource = d: \ accessData. mdb; uid = sa; pwd = dd ";
SQL SERVERCopy codeThe Code is as follows: stringconStr = @ "Server = bwj; database = demo; uid = sa; pwd = ";
ORACLECopy codeThe Code is as follows: stringconStr = @ "Provider = MSDAORA.1; Password = pwd; UserID = user_name; Data Source = link_str"