ado.net
connect 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.
}
Connect to 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.
}
Connect to 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.
}
Connect to Oracle data source
Oracle. NET Framework data providers use 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: <span class="Apple-converted-space"></span>
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 "