Various methods for connecting to the ADO database (think about it if you forget it)

Source: Internet
Author: User
Tags oracleconnection connection reset

Database Connection Method in ado.net (provided by Microsoft)

Microsoft provides the following four Database Connection Methods:
System. Data. oledb. oledbconnection
System. Data. sqlclient. sqlconnection
System. Data. ODBC. odbcconnection
System. Data. oracleclient. oracleconnection
In the following example, we will explain in sequence:

System. Data. sqlclient. sqlconnection
Some commonly used connection strings (C #Code):

Sqlconnection Conn
= New sqlconnection ("Server = (local); Integrated Security = sspi; database = pubs ");

Sqlconnection Conn
= New sqlconnection ("Server = (local) \ netsdk; database = pubs; Integrated Security = sspi ");

Sqlconnection conn = new sqlconnection (
"Data Source = localhost; Integrated Security = sspi; initial catalog = northwind ;");

Sqlconnection conn = new sqlconnection (
"Data Source = (local); initial catalog = XR; Integrated Security = sspi;
Persist Security info = false; workstation id = xurui; packet size = 4096 ;");

Sqlconnection myconn = new
System. Data. sqlclient. sqlconnection ("Persist Security info = false; Integrated
Security = sspi; database = northwind; server = mysqlserver ");

Sqlconnection conn = new sqlconnection (
"Uid = sa; Pwd = passwords; initial catalog = pubs; Data Source = 127.0.0.1; Connect timeout = 900 ");

For more string connection instructions, see msdn:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdatasqlclientsqlconnectionclassconnectionstringtopic. asp

System. Data. oledb. oledbconnection
Commonly used connection strings (C # code ):

Oledbconnection conn = new oledbconnection (@ "provider = Microsoft. Jet. oledb.4.0; Data Source = D: \ myweb \ 81 \ 05 \ grocertogo. mdb ");

Oledbconnection conn = new oledbconnection (
@ "Provider = Microsoft. Jet. oledb.4.0; Password =;
User ID = admin; Data Source = grocertogo. mdb ;");

Oledbconnection conn = new oledbconnection (
"Provider = msdaora; Data Source = oracle8i7; persist Security info = false; Integrated Security = yes ");

Oledbconnection conn = new oledbconnection (
"Provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ bin \ localaccess40.mdb ");

Oledbconnection conn = new oledbconnection (
"Provider = sqloledb; Data Source = mysqlserver; Integrated Security = sspi ");

For more string connection instructions, see msdn:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdataoledboledbconnectionclassconnectionstringtopic. asp? Frame = true

System. Data. oracleclient. oracleconnection
Commonly used connection strings (C # code ):

Oracleconnection myconn = new system. Data. oracleclient. oracleconnection (
"Data Source = Oracle8i; Integrated Security = yes ");

 

For more string connection instructions, see msdn:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdataoracleclientoracleconnectionclassconnectionstringtopic. asp? Frame = true

System. Data. ODBC. odbcconnection
Commonly used connection strings (C # code ):

Odbcconnection conn = new odbcconnection (
"Driver = {SQL Server}; server = myserver; trusted_connection = yes; database = northwind ;");

Odbcconnection conn = new odbcconnection (
"Driver = {Microsoft ODBC for Oracle}; server = oracle8i7;
Persist Security info = false; trusted_connection = yes ");

Odbcconnection conn = new odbcconnection (
"Driver = {Microsoft Access Driver (*. mdb)}; DBQ = c: \ bin \ nwind. mdb ");

Odbcconnection conn = new odbcconnection (
"Driver = {Microsoft Excel Driver (*. xls)}; DBQ = c: \ bin \ book1.xls ");

Odbcconnection conn = new odbcconnection (
"Driver = {Microsoft text Driver (*. txt; *. CSV)}; DBQ = c: \ bin ");

Odbcconnection conn = new odbcconnection ("DSN = dsnname ");

For more string connection instructions, see msdn:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdataodbcodbcconnectionclassconnectionstringtopic. asp? Frame = true

Database connections provided by other vendors:

Db2connection myconn = new IBM. Data. db2.db2connection (
"Database = sample; uid = <username>; Pwd = <password> ;");

Db2connection myconn = new IBM. Data. db2.db2connection ("database = sample ");

Bdpconnection myconn = new Borland. Data. provider. bdpconnection ("assembly = borl
And. Data. MSSQL, version = 1.1.0.0, culture = neutral, publickeytoken = 91d62ebb5b0d1b1b; ve
Ndorclient = sqloledb. dll; osauthentication = false; database = <database>; usernam
E = <user>; hostname =

Bdpconnection myconn = new Borland. Data. provider. bdpconnection ("assembly = borl
And. Data. DB2, version = 1.1.0.0, culture = neutral, publickeytoken = 91d62ebb5b0d1b1b; ve
Ndorclient = db2cli. dll; database = <database>; username = <user>;
Password = <password>; provider = DB2 ");

Connection Pooling


Data providers in the SQL Server, OLE DB, And. Net frameworks provide support for implicit connection pool connections. You can specify different parameter values in connectionstring to control the action of the connection pool. For example, the following example invalidates the ole db connection pool and automatically processes transactions:
Provider = sqloledb; ole db services =-4; Data Source = localhost; Integrated Security = sspi;
The following parameters are provided in SQL Server. NET data provider to control the connection pool behavior: Connection lifttime, Connection Reset, enlist, Max pool size, Min pool size, and pooling.

For more database connection information and non-ado.net connection strings, see:
Http://www.connectionstrings.com/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.