. NET of various database connection Daquan

Source: Internet
Author: User
Tags ibm db2 connect odbc mysql ole oracleconnection sybase connection reset

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


OLE DB, 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 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))
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 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 ()


Data Shape


MS Data Shape
"Provider=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; "

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 The length of time (in seconds) to wait for a Connection to the server before terminating the attemp T and generating an error.
Connection Lifetime 0 When a Connection was returned to the pool, its creation time is compared with the current time, and The connection is destroyed 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 ' if true, the pooler automatically enlists the connection in the creation thread ' s current transaction cont Ext.
Initial Catalog
-or-
Database The name of the database.
Integrated security
-or-
Trusted_Connection ' false ' Whether the Connection is to being a secure Connection or not. Recognized values are ' true ', ' false ', and ' SSPI ', which is equivalent to ' true '.
Max Pool Size 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 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 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 on.
Persist security Info ' false ' if set to ' false ', security-sensitive information, such as the password, are not returned a s part of the connection if the connection are open or has ever been in a open state. Resetting the connection string resets all connection string values including the password.
Pooling ' true ' if true, the SqlConnection object is drawn from the appropriate pool, or if necessary, is created and add Ed to the appropriate 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.
Access
Odbc


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


OLE DB, OleDbConnection (. NET)


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


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


OLE DB, OleDbConnection (. NET)


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


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


Data Shape


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


Mysql
Odbc


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


OLE DB, 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 was 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 ()


IBM DB2
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 "


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


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)};D Riverid=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;" indicates that the "the" "the" contains ColumnNames
Dbf/foxpro
Odbc


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


OLE DB, 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;"





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.