.NET in various database connectivity

zhaozj2021-02-16  79

SQL Server

ODBC

Standard Security:

"Driver = {SQL Server}; server = aron1; data = 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 = public;"

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") = adpromptalways

Oconn.open "Data Source = aron1; initial catalog = public;"

Connect Via An 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 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.sqlclient

DIM OSQLCONN AS SQLCONNECTION = New SqlConnection ()

Osqlconn.connectionstring = "my connectionstring"

Osqlconn.open ()

Data Shape

MS Data Shape

"Provider = msdatashape; data provides = 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 Library = DBMSSOCN

And when connecting through msdasql provider use the syntax network = dbmsoCN

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.

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, incruding the full path name, of an attachable database. The Database name must be specified with the keyword 'database'.

Connect Timeout

-or-

............................... ...CRIPLILE, TEAC701.

Connection Lifetime 0 When 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 whether the database connection is reset when being removed from the pool. Setting to 'false' avoids making 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 Pool 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 to be 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 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.

.

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.

Pool '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 id the local computer name the name of the workstation connection 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 not change the connectionstring by inserting an Additional property with another value covered.

ACCESS

ODBC

Standard Security:

"Driver = {Microsoft Access Driver (* .mdb)}; dbq = / somepath / mydb.mdb; uid = admin; pwd = asdasd;"

Workgroup:

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

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}; connectionString = oracleserver.world; uid = myusername; pwd = mypassword;"

OLEDB, 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.racle; data source = myoracledb; user id = username; password = asdasd;" Trusted Connection:

"Provider = oraoledb.racle; 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.oraclient;

OracleConnection OracleConn = New OracleConnection ();

Oracleconn.connectionstring = "my connectionstring";

Oracleconn.open ();

VB.NET:

Imports system.data.OracleClient

DIM OracleConn As OracleConnection = New OracleConnection ()

Oracleconn.connectionstring = "my connectionstring"

Oracleconn.open ()

Data Shape

MS Data Shape:

"Provider = msdatashape.1; Persist security info = false; data source = msdara; 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 =; dataBase = my-data; 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.mysqlclient

Dim omysqlconn as mysqlconnection = new mysqlconnection ()

omysqlconn.connectionstring = "my connectionstring"

omysqlconn.open ()

IBM DB2

OLEDB, 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 = ''; driver = {informix 3.30 32 bit}; host = hostname; service = myserver; service = service-name; protocol = ilSoctcp; 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 profrs = excel 8.0; hdr = yes;" "HDR = yes;" INDICATES That The First Row Contains ColumnNames, NOT DATA

DBF / FOXPRO

ODBC

STANDARD:

"Driver = {Microsoft DBase Driver (* .dbf)}; 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.ud;"

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

New Post(0)