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.oledbconnectionsystem.data.sqlclient.sqlconnectionsystem.data.odbc.odbcconnectionsystem.data.OracleClient.OracleConnection Let's explain the way, in order to explain:
Some connection strings (C # code) common to System.Data.SqlClient.SqlConnection (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); INTEGRATED security = SSPI; persist security info = false; Workstation ID = xr; 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 notes See msdn: http://msdn.microsoft.com/library/default.asp? URL = / library / en-us / cpref / html / frsrfsystemDataSqlclientsqlConnectionClassConnectionstringtopic.asp
Some connection strings (C # code) commonly used by system.Data.oledb.oledbConnection (C # code):
OLEDBCONNECTION CONN = New OLEDBCONNECTION (@ "provider = microsoft.jet.oledb.4.0; data source = d: /myweb5/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");
More string concatenation Description see MSDN: http:? //Msdn.microsoft.com/library/default.asp url = / library / en-us / cpref / html / frlrfSystemDataOleDbOleDbConnectionClassConnectionStringTopic.asp frame = trueSystem.Data.OracleClient? Some connection strings (C # code) commonly used in. OracleConnection: OracleConnection myconn = new system.data.OracleClient.OracleConnection ("Data Source = ORACLE8I; Integrated Security = YES");
More string concatenation Description see MSDN: http: //msdn.microsoft.com/library/default.asp url = / library / en-us / cpref / html / frlrfSystemDataOracleClientOracleConnectionClassConnectionStringTopic.asp frame = trueSystem.Data.Odbc?? Some connection strings (C # code) ("driver = {sql server = new odbcconnection conn = new odbcconnection (" driver = {sql server = new odbcconnection):
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 / fr1rfsystemDataodBCODBCCCONNECLASSCONNECTIONSTRINGTOPIC.ASP? Frame = true
Database connection provided by other vendors:
DB2Connection myconn = new ibm.data.db2.db2connection ("Database = Sample; UID =
DB2Connection myconn = new ibm.data.db2.db2connection ("Database = Sample");
BdpConnection myConn = new Borland.Data.Provider.BdpConnection ( "assembly = Borland.Data.Mssql, Version = 1.1.0.0, Culture = neutral, PublicKeyToken = 91d62ebb5b0d1b1b; vendorclient = sqloledb.dll; osauthentication = False; database =
BdpConnection myConn = new Borland.Data.Provider.BdpConnection ( "assembly = Borland.Data.Db2, Version = 1.1.0.0, Culture = neutral, PublicKeyToken = 91d62ebb5b0d1b1b; vendorclient = db2cli.dll; database =
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 connecting pool in effect and automatically transaction: provider = sqloledb; OLE DB Services = -4; Data Source = localhost; integrated security = SSPI; below SQL Server.net Data Provider Parameter Setting Control Connection Pool Behavior: Connection Lifttime, Connection Reset, Enlist, Max Pool Size, Min Pool Size and Published on September 06, 2004 12:25 PM
comment
#
Reply: Database connection in ADO.NET (provided by Microsoft)
2004-09-06 7:57 PM
Cry_out
With the ODBC connection, what to use That Command? SqlConnection is SQLCommand, OLEDBConnection is OLEDBConnection, then use the ODBC, what to use That Command?
#
Reply: Database connection in ADO.NET (provided by Microsoft)
2004-09-07 10:45 AM
Abao
Of course there is ODBCCommand
Http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdataodbcodbccommandclastopic.asp?frame=true
For a list of all members of this type, see odbccommand members.
System.Object
System.MarshalByrefObject
System.componentmodel.component
System.data.odbc.odbccommand
[Visual Basic]
Notinheritable public class otbccommand
Inherits Component
Implements icloneable, IDBCommand
[C #]
Public Sealed Class Odbccommand: Component, Icloneable, IDBCommand
[C ]
Public __gc __sealed class odbccommand: Public Component,
Icloneable, IDBCommand
[Jscript]
Public Class Odbccommand Extends Component Implements iCloneable,
IDBCommand
#
Reply: Database connection in ADO.NET (provided by Microsoft)
2004-09-07 10:46 AM
Abao
[C #]
Public void readmyData (String myConnString)
{
String myselectQuery = "Select ORDERID, Customerid from Orders";
OdbcConnection myconnection = new odbcconnection;
Odbccommand mycommand = new odbccommand (MySelectQuery, MyConnection);
MyConnection.open ();
ODBCDataReader myreader = mycommand.executereader (); TRY
{
While (MyReader.Read ())
{
Console.Writeline (MyReader.GetInt32 (0) "," MyReader.getstring (1));
}
}
Finally
{
// ALWAYS CALL Close When Done with connect.
MyReader.Close ();
// ALWAYS CALL Close When Done with connect.
MyConnection.Close ();
}
}