ADO.NET Database Connection Mode CARPER (original)
Keywords ADO.NET Database connection method
In the MSDN, the .NET's database connection string has a detailed description, I am here with code examples, and the meaning of each representative can see MSDN.
Database connection 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
Below we will explain in the way:
System.data.sqlclient.sqlconnection
Some common 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; connection timeout = 900");
More string connection instructions, please see MSDN:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemDataSqlClientSqlConnectionClassConnectionstringtopic.asp
System.Data.Oledb.oledbconnection
Some common 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 = mysqlser; integrated security = sspi");
More string connection instructions, please see MSDN:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemDataoledboledbconnectionclassConnectionstringtopic.asp?frame=true
System.Data.OracleClient.OracleConnection
Some common connection strings (C # code):
OracleConnection myconn = new system.data.racleClient.OracleConnection
"Data Source = Oracle8i; Integrated Security = YES");
More string connection instructions, please see MSDN:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemDataracleClientoConnectionClassConnectionstringtopic.asp?frame=true
System.Data.odbc.odbcconnection
Some common connection strings (C # code):
ODBCCONNECTION CONN = New ODBCCONNECTION
"Driver = {SQL Server}; server = myserver; trusted_connection = yes; data = 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");
More string connection instructions, please see MSDN:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemDataodbcodbcConnectionClassConnectionstringtopic.asp?frame=true
Database connection provided by other vendors:
DB2Connection myconn = new ibm.data.db2.db2connection
"Database = Sample; UID =
; PWD =
");
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 =
Usernam
e =
Hostname =
Password =
"provider = mssql");
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 =
Username =
;
PASSWORD =
; provider = db2 ");
Connection Pooling
In the Data Provider in SQL Server, OLE DB, and .NET Framework, implicit connection pool connection support is provided. You can specify different parameter values to control the behavior of the connection pool in Connectionstring. For example, the following example makes the OLE DB connection pool and automatically perform transaction processing:
Provider = SQLOLEDB; OLE DB SERVICES = -4; Data Source = localhost; integrated security = SSPI; provides the following parameter settings in SQL Server.Net Data Provider: Connection LiftTime, Connection Reset, Enlist, Max Pool Size, MIN Pool Size and Pooling.
More database connection information, as well as non-ADO.NET connection strings can be found:
http://www.connectionstrings.com/