ADO.NET Database connection method

xiaoxiao2021-03-06  58

In MSDN, the .NET's database connection string has a detailed description, I have some ways of code examples, and the meaning of each representative can be found in the MSDN. ADO.NET Database connection method (Microsoft is provided) Microsoft provides the following four database connection: System.Data.OleDb.OleDbConnectionSystem.Data.SqlClient.SqlConnectionSystem.Data.Odbc.OdbcConnectionSystem.Data.OracleClient.OracleConnection Here we have an example of the way in order to explain: System.Data. SqlClient.SqlConnection some common connection string (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 SQLC Onnection ("UID = SA; PWD = Passwords; Initial Catalog = Pubs; Data Source = 127.0.0.1; connection timeout = 900"); More String Connections 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 string (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 "); More string connection notes 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 string (C # Code): 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 = true System.Data??. O dbc.OdbcConnection some common connection string (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"); more string concatenation Description 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 = 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; Vendorc Lient = db2cli.dll; database = ; username = ; password = ; provider = dB2 "); Connection Pool in the Data Provider in SQL Server, Ole DB, and .NET Framework Structure, Provides implicit connector connection support. 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 Settings Control Connection Pool: Connection LiftTime, Connection Reset, Enlist, Max Pool Size, Min Pool Size and Pooling.

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

New Post(0)