Database connection in ADO.NET (provided by Microsoft)

xiaoxiao2021-03-06  67

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 = ; pwd = ;");

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 = Username = ; hostname = ; password = ; provider = mssql ");

BdpConnection myConn = new Borland.Data.Provider.BdpConnection ( "assembly = Borland.Data.Db2, Version = 1.1.0.0, Culture = neutral, PublicKeyToken = 91d62ebb5b0d1b1b; vendorclient = db2cli.dll; database = ; username = < User>; password = ; provider = dB2 ");

Connection Pooling

转载请注明原文地址:https://www.9cbs.com/read-119918.html

New Post(0)