Database connection

xiaoxiao2021-03-06  123

.NET in various database connectivity

SQL Server

ODBC

Standard Security: "Driver = {SQL Server}; Server = Aron1; Database = pubs; Uid = sa; Pwd = asdasd;" Trusted connection: "Driver = {SQL Server}; Server = Aron1; Database = pubs; Trusted_Connection = yes "" Prompt for username and password: Oconn.properties ("prompt") = adpromptalwaysoconn.open "driver = {SQL Server}; server = aron1; database = pubs;" OLEDB, OLEDBConnection (.NET)

Standard Security: "Provider = sqloledb; Data Source = Aron1; Initial Catalog = pubs; User Id = sa; Password = asdasd;" Trusted Connection: "Provider = sqloledb; Data Source = Aron1; Initial Catalog = pubs; Integrated Security = SSPI "

(Use Servername / InstanceName As Data Source To Use An Specifik Sqlserver Instance, "ONLY SQLSERVER2000)

Prompt for username and password: oConn.Provider = "sqloledb" oConn.Properties ( "Prompt") = adPromptAlwaysoConn.Open "Data Source = Aron1; Initial Catalog = pubs;" Connect via an IP address: "Provider = sqloledb; Data Source = 190.190.200.100, 1433; network library = dbms SOCN; Initial Catalog = Pubs; user ID = sa; password = asdasd; "

(DBMSSOCN = TCP / IP INSTEAD OF NAMED PIPES, AT THE End of The Data Source Is The Port To Use (1433 Is The Default))

SqlConnection (.NET)

Standard security: "data source = aron1; initial catalog = pubs; user ID = sa; password = asdasd;" trusted connection: "data source = aron1; initial catalog = pubs; integrated security = sspi;"

(Use Servername / InstanceName As Data Source To Use An Specifik Sqlserver Instance, "ONLY SQLSERVER2000)

Connect via an IP address: "Data Source = 190.190.200.100,1433; Network Library = DBMSSOCN; Initial Catalog = pubs; User ID = sa; Password = asdasd;" (DBMSSOCN = TCP / IP instead of Named Pipes, at the end Of the data source is the port to use (1433 is the default))

Declare the SqlConnection:

C #: using System.Data.SqlClient; SqlConnection oSQLConn = new SqlConnection (); oSQLConn.ConnectionString = "my connectionstring"; oSQLConn.Open (); VB.NET:Imports System.Data.SqlClientDim oSQLConn As SqlConnection = New SqlConnection () Osqlconn.connectionstring = "My Connectionstring" osqlconn.open ()

Data Shape

MS Data Shape "Province = msdatashape; data provider = sqloledb; data source = aron1; initial catalog = pubs; user ID = sa; password = asdasd;" Read More

How To Define Wich Network Protocol To Use

Example: "provider = SQLOLEDB; DATA SOURCE = 190.190.200.100, 1433; network library = dbmssocn; initial catalog = pubs; user ID = sa; password = asdasd;"

NameNetwork librarydbnmpntwWin32 Named PipesdbmssocnWin32 Winsock TCP / IPdbmsspxnWin32 SPX / IPXdbmsvinnWin32 Banyan VinesdbmsrpcnWin32 Multi-Protocol (Windows RPC) Important note! When connecting through the SQLOLEDB provider use the syntax Network Library = dbmssocnand when connecting through MSDASQL provider use the syntax Network = dbmssocn

All SqlConnection Connectionstring Properties

This Table Shows All Connectionstring Properties for the ado.net sqlConnection Object. Most of the Properties Area ALSO Used in ado. All Properties and descriptions is from msdn.

NameDefaultDescriptionApplication Name The name of the application, or '.Net SqlClient Data Provider' if no application name is provided.AttachDBFilename-or-extended properties-or-Initial File Name The name of the primary file, including the full path name, of an attachable database. The database name must be specified with the keyword 'database'.Connect Timeout-or-Connection Timeout15The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.Connection Lifetime0When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by connection lifetime. Useful in clustered configurations to force load balancing between a running server And A Server Just BROUGHT On-line.connection reset'true'determines WHENER THE DATABASE Connection Is Reset When Removed from The pool. Setting to 'False' Avoids MAK ing an additional server round-trip when obtaining a connection, but the programmer must be aware that the connection state is not being reset.Current Language The SQL Server Language record name.Data Source-or-Server-or-Address-or-Addr -or-Network address The name or network address of the instance of SQL Server to which to connect.Enlist'true'When true, the pooler automatically enlists the connection in the creation thread's current transaction context.Initial Catalog-or-Database The name ORSE 'WRUSTED_CONNECTION' FALSED VALUES ARE 'TRUE', 'FALSE', AND 'SSPI'

, Which is equivalent to 'true'.Max Pool Size100The maximum number of connections allowed in the pool.Min Pool Size0The minimum number of connections allowed in the pool.Network Library-or-Net'dbmssocn'The network library used to establish a connection to an instance of SQL Server. Supported values ​​include dbnmpntw (Named Pipes), dbmsrpcn (Multiprotocol), dbmsadsn (Apple Talk), dbmsgnet (VIA), dbmsipcn (Shared Memory) and dbmsspxn (IPX / SPX), and dbmssocn (TCP / IP). The Corresponding Network DLL Must Be Installed on The System To Which You Connect. If You Use A Local Server (for Example, "), Shared Memory IS Used .Packet Size8192Size in bytes of the network packets used to communicate with an instance of SQL Server.Password-or-Pwd The password for the SQL Server account logging on.Persist Security Info'false'When set to 'false', security-sensitive Information, Such As the Password, IS NOT RETURNED AS Part of the Connection If The Connection is open or has ever been in an open state. Resetting the connection string resets all connection string values ​​including the password.Pooling'true'When true, the SQLConnection object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool.User ID The SQL Server login account.Workstation IDthe local computer nameThe name of the workstation connecting to SQL Server.Note Use; to separate each property.If a name occurs more than once, the value from the last one in the Connectionstring Will Be Used.if You Are Building Your Connectionstring In Your App Using Values ​​from User Input Fields, Make Sure The User Can '

T change the connectionString by Inserting An Additional Property with Another Value Withnin The user value.access

ODBC

Standard Security: "Driver = {Microsoft Access Driver (* .mdb)}; dbq = / somepath / mydb.mdb; uid = admin; pwd = asdasd;" Workgroup: "driver = {Microsoft Access Driver = {Microsoft Access Driver (* .mdb)} DBQ = / somepath / mydb.mdb; systemdb = / somepath / mydb.mdw; "," admin "," "OLEDB, OLEDBConnection (.NET)

Standard security: "provider = microsoft.jet.OLEDb.4.0; data source = / somepath / mydb.mdb; user ID = admin; password = asdasd;" Workgroup (system database): "provike = microsoft.jet.Oledb.4.0 Data Source = / SomePath / MyDb.mdb; Jet OLEDB: System Database = System.mdw; "," Admin "," "" with password: "provider = microsoft.jet.Oledb.4.0; data source = / somepath / mydb .mdb; Jet OLEDB: Database password = mydbpassword; "," admin "," "

Oracle

ODBC

New version: "Driver = {Microsoft ODBC for Oracle}; Server = OracleServer.world; Uid = Username; Pwd = asdasd;" Old version: "Driver = {Microsoft ODBC Driver for Oracle}; ConnectString = OracleServer.world; Uid = Myusername; PWD = mypassword; "OLEDB, OLEDBCONNECTION (.NET)

Standard Security: "provider = msdara; data source = myoracledb; user id = username; password = asdasd;"

This One's from Microsoft, The Following Are from Oracle, THE FLLOWING ARE

Standard Security: "Provider = OraOLEDB.Oracle; Data Source = MyOracleDB; User Id = Username; Password = asdasd;" Trusted Connection: "Provider = OraOLEDB.Oracle; Data Source = MyOracleDB; OSAuthent = 1;" OracleConnection (.NET)

Standard: "Data Source = Oracle8i; Integrated Security = YES"; This One Works Only with Oracle 8i Release 3 or Later

Declare the OracleConnection:

C #: using System.Data.OracleClient; OracleConnection oOracleConn = new OracleConnection (); oOracleConn.ConnectionString = "my connectionstring"; oOracleConn.Open (); VB.NET:Imports System.Data.OracleClientDim oOracleConn As OracleConnection = New OracleConnection () Oracleconn.connectionstring = "my connectionstring" oracleconn.open ()

Data Shape

MS Data Shape: "Provider = MSDataShape.1; Persist Security Info = False; Data Provider = MSDara; Data Source = ORAC; User ID = UserName; Password = MYPW"

Mysql

ODBC

Local Database: "Driver = {mysql}; server = mysrvname; option = 16834; data = mydatabase;" Remote Database: "driver = {mysql}; server = data.domain.com; port = 3306; option = 131072; STMT =; Database = my-database; uid = username; pwd = password; "OLEDB, OLEDBCONNECTION (.NET)

Standard: "provider = mysqlprov; data source = mydb; user id = username; password = asdasd;" MySQLConnection (.NET)

EID: "Data Source = Server; Database = MYDB; User ID = Username; Password = PWD; Command Logging = FALSE"

This One is used with einfodesigns dbprovider, an add-on to .net

Declare the mysqlconnection:

C #: using EID.MySqlClient; MySqlConnection oMySqlConn = new MySqlConnection (); oMySqlConn.ConnectionString = "my connectionstring"; oMySqlConn.Open (); VB.NET:Imports EID.MySqlClientDim oMySqlConn As MySqlConnection = New MySqlConnection () oMySqlConn.ConnectionString = "My Connectionstring" omysqlconn.open ()

IBM DB2

OLEDB, OleDbConnection (.NET) from msTCP / IP: "Provider = DB2OLEDB; Network Transport Library = TCPIP; Network Address = XXX.XXX.XXX.XXX; Initial Catalog = MyCtlg; Package Collection = MyPkgCol; Default Schema = Schema; User ID = MyUser; Password = myPW "APPC:" Provider = DB2OLEDB; APPC Local LU Alias ​​= MyAlias; APPC Remote LU Alias ​​= MyRemote; Initial Catalog = MyCtlg; Package Collection = MyPkgCol; Default Schema = Schema; User ID = MyUser; Password = Mypw "

Sybase

ODBC

Standard: "Driver = {SYBASE SYSTEM 11}; Srvr = Aron1; Uid = username; Pwd = password;" Intersolv 3.10: "Driver = {INTERSOLV 3.10 32-BIT Sybase}; Srvr = Aron1; Uid = username; Pwd = password "

Informix

ODBC

Informix 3.30: "Dsn = ''; Driver = {INFORMIX 3.30 32 BIT}; Host = hostname; Server = myserver; Service = service-name; Protocol = olsoctcp; Database = mydb; UID = username; PWD = myPwd Informix-CLI 2.5: "Driver = {INFORMIX-CLI 2.5 (32 Bit)}; server = myserver; database = mydb; uid = username; pwd = mypwd

DSN

ODBC

DSN: "DSN = MyDSN; UID = Username; PWD =;" File DSN: "FileDSN = C: /MYDATA.DSN; UID = UserName; PWD =;"

Excel

ODBC

Standard: "Driver = {Microsoft Excel Driver (* .xls)}; driverid = 790; dbq = c: /myexcel.xls; defaultdir = c: / mypath;" OLE DB

Standard: "provider = microsoft.jet.Oledb.4.0; data source = c: /myexcel.xls; extended Properties = Excel 8.0; HDR = yes;"

"HDR = yes;" INDICES That The First Row Contains ColumnNames, Not Data

DBF / FOXPRO

ODBC

Standard: "Driver = {Microsoft DBase Driver (* .db)}; driverid = 277; DBQ = C: / mydbpath;" OLEDB, OLEDBCONNECTION (.NET) Standard: "provider = microsoft.jet.Oledb.4.0; data source = C: / folder; Extended Properties = DBASE IV; user ID = admin; password = "

Pervasive

ODBC

Standard: "Driver = {Pervasive ODBC Client Interface}; servername = srvname; dbq = @ dbname"

UDL UDL UDL: "File Name = C: /MYDATALINK.UDL;"

Explore: http://www.connectionstrings/

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

New Post(0)