ado.net
Connecting to SQL Server
The SQL Server. NET Framework Data Provider supports a connection string format similar to the OLE DB (ADO) connection string format.
Copy Code code as follows:
using (SqlConnection connection = new SqlConnection (connectionString))
{
Connection. Open ();
Do work here.
}
Connecting to an OLE DB data source
The OLE DB. NET Framework Data Provider provides a connection to a data source exposed by using OLE DB and with Microsoft SQL Server 6.x or earlier, through the OleDbConnection object, for SQL Server OLE DB Provider (SQLOLEDB)) connection.
Copy Code code as follows:
using (OleDbConnection connection = new OleDbConnection (connectionString))
{
Connection. Open ();
Do work here.
}
Connecting to an ODBC data source
The ODBC. NET Framework Data Provider provides a connection to a data source exposed by using ODBC through the OdbcConnection object.
Copy Code code as follows:
using (odbcconnection connection = new OdbcConnection (connectionString))
{
Connection. Open ();
Do work here.
}
Connecting to an Oracle data source
The Oracle. NET Framework Data Provider uses the OracleConnection object to provide a connection to an Oracle data source.
Copy Code code 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 connection instances:
ACCESS
Copy Code code as follows:
stringconstr=@ "Provider=microsoft. Jet.oledb.4.0;datasource=d:\\accessdata.mdb;uid=sa;pwd=dd ";
SQL SERVER
Copy Code code as follows:
stringconstr=@ "server=bwj;database=demo;uid=sa;pwd=";
ORACLE
Copy Code code as follows:
stringconstr=@ "Provider=MSDAORA.1; Password=pwd; Userid=user_name;data Source=link_str "