Asp. NET of various database connection Daquan

Source: Internet
Author: User
Tags dbase informix odbc ole oracleconnection sybase connection reset win32

SQL Server ODBC OLE DB, OleDbConnection (. net) SqlConnection (. net) Data Shape Read more ACCESS Oracle MySQL IBM D B2 Sybase Informix DSN Excel dbf/foxpro Pervasive UDL

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") = adPromptAlways
oConn.Open "Driver={sql Server}; Server=aron1;database=pubs; "



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 SQL Server instance, only SQLServer2000)Prompt for username and password:
Oconn.provider = "SQLOLEDB"
Oconn.properties ("Prompt") = adPromptAlways
oConn.Open "Data source=aron1;initial catalog=pubs;"

Connect via a IP address:
"Provider=sqloledb;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 "the" of the Data Source is the port to use (1433 is the default))

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 SQL Server instance, only SQLServer2000)Connect via a 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 "the" 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.SqlClient
Dim Osqlconn As SqlConnection = New SqlConnection ()
Osqlconn.connectionstring= "My ConnectionString"
Osqlconn.open ()



MS Data Shape
"Provider=msdatashape;data provider=sqloledb;data source=aron1;initial catalog=pubs; User Id=sa; PASSWORD=ASDASD; "



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; "

Name Network Library
Dbnmpntw Win32 Named Pipes
Dbmssocn Win32 Winsock TCP/IP
Dbmsspxn Win32 spx/ipx
Dbmsvinn Win32 Banyan Vines
Dbmsrpcn Win32 multi-protocol (Windows RPC)


Important note!
When connecting through the SQLOLEDB provider use the syntax network
And 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 are also used in ADO. All properties and descriptions are from MSDN.

Name Default Description
Application 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, and an attachable database. The database name must is specified with the keyword ' database '.
Connect Timeout
-or-
Connection Timeout
15 The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an ER Ror.
Connection Lifetime 0 When a connection are returned to the pool, its creation time is compared with the "current", and the connection is dest royed If this 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.
Connection Reset ' True ' Determines whether the database connection is reset when being removed from the pool. Setting to ' false ' avoids making of additional server round-trip when obtaining a connection, but the programmer must Ware that "connection" 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 of the database.
Integrated security
-or-
Trusted_Connection
' False ' Whether The connection is a secure connection or not. Recognized values are ' true ', ' false ', and ' SSPI ', which is equivalent to ' true '.
Max Pool Size 100 The maximum number of connections allowed in the pool.
Min Pool Size 0 The minimum number of connections allowed in the pool.
Network Library
-or-
Net
' DBMSSOCN ' The network library used to establish a connection to a 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 is installed on the system to which you connect. If you don't specify a network and use a local server (for example, "." or "(local)"), the shared memory is used.
Packet Size 8192 Size in bytes of the network packets used to communicate with a instance of SQL Server.
Password
-or-
Pwd
The password for the SQL Server account logging.
Persist Security Info ' False ' When set to ' false ', security-sensitive information, such as the password, are not returned as part of the connection if th E connection is the open or has ever been in a open state. Resetting the connection string resets all connection string values including the password.
Pooling ' True ' When True, the SqlConnection object was drawn from the appropriate pool, or if necessary, are created and added to the Appro Priate pool.
User ID The SQL Server login account.
Workstation ID The local computer name The name of the workstation connecting to SQL Server.


Note
use; To separate the property.
If a name occurs more than once, the value from the last one in the ConnectionString would be used.
If you are are building your connectionstring in your app. using values from user input fields, make sure the user can ' t    The ConnectionString by inserting a additional property with another value within the user value. ODBC OLE DB, OleDbConnection (. NET)

Standard Security:
"Driver={microsoft ACCESS Driver (*.mdb)};D Bq=/somepath/mydb.mdb; Uid=admin; PWD=ASDASD; "

Workgroup:
"Driver={microsoft ACCESS Driver (*.mdb)};D Bq=/somepath/mydb.mdb; systemdb=/somepath/mydb.mdw; "," admin "," "



Standard Security:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb; User id=admin; PASSWORD=ASDASD; "

Workgroup (System database):
"Provider=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 "," "

ODBC OLE DB, OleDbConnection (. net) OracleConnection (. net) Data Shape

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; "



Standard Security:
"Provider=msdaora;data Source=myoracledb; User Id=username; PASSWORD=ASDASD; " This one's from Microsoft, the following are from Oracle Standard Security:
"Provider=oraoledb.oracle;data Source=myoracledb; User Id=username; PASSWORD=ASDASD; "

Trusted Connection:
"Provider=oraoledb.oracle;data source=myoracledb;osauthent=1;"



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.OracleClient
Dim ooracleconn as OracleConnection = New OracleConnection ()
ooracleconn.connectionstring = "My ConnectionString"
Ooracleconn.open ()



MS Data Shape:
"PROVIDER=MSDATASHAPE.1; Persist security info=false;data provider=msdaora;data source=orac;user ID=USERNAME;PASSWORD=MYPW "

ODBC OLE DB, OleDbConnection (. net) mysqlconnection (. net)

Local database:
"Driver={mysql}; Server=mysrvname;option=16834;database=mydatabase; "

Remote Database:
"Driver={mysql}; server=data.domain.com; port=3306;option=131072; stmt=;D atabase=my-database; Uid=username; Pwd=password; "



Standard:
"Provider=mysqlprov;data Source=mydb; User Id=username; PASSWORD=ASDASD; "

EID:
"Data Source=server;database=mydb; User Id=username; Password=pwd; Command Logging=false "This one's used with einfodesigns Dbprovider, a 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. Mysqlclient
Dim omysqlconn as Mysqlconnection = New mysqlconnection ()
omysqlconn.connectionstring = "My ConnectionString"
Omysqlconn.open ()

OLE DB, OleDbConnection (. NET) from MS

TCP/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 "

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; "

Odbc

Informix 3.30:
"Dsn= '";D river={informix 3.30 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" (Bit)}; Server=myserver;database=mydb; Uid=username; Pwd=mypwd "

Odbc

DSN:
"DSN=MYDSN; Uid=username; pwd=; "

File DSN:
"FILEDSN=C:/MYDATA.DSN; Uid=username; pwd=; "

ODBC OLE DB

Standard:
"Driver={microsoft Excel Driver (*.xls)};D Riverid=790;dbq=c:/myexcel.xls;defaultdir=c:/mypath;"



Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/myexcel.xls; Extended Properties=excel 8.0; Hdr=yes; " "Hdr=yes;" indicates that the "the" "the" the "the" contains ColumnNames, not data ODBC OLE DB, OleDbConnection (. NET)

Standard:
"Driver={microsoft DBASE Driver (*.dbf)};D Riverid=277;dbq=c:/mydbpath;"



Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/folder; Extended properties=dbase IV; User id=admin; Password= "

Odbc

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

UDL

UDL:
"File name=c:/mydatalink.udl;"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.