Connection database query Manual (not only for ASP)

Source: Internet
Author: User
Tags manual dsn odbc ole query safety mode first row
The following is a brief introduction to several ADO connection methods: ODBC dsn,odbc dsn-less,
OLE DB Provider, and "MS Remote" Provider.
1. ODBC DSN Connection
I.dsn
oConn.Open "Dsn=advworks" & _
"Uid=admin;" & _
"Pwd=;"
Note: It is not possible to use this method from the beginning of MDAC2.1, that is, just place the DSN file name in the ConnectString
You must use the DSN,UID,PWD logo at the same time. For example, the following method will error in MDAC 2.1:
oConn.Open "AdvWorks"



Ii. File DSN
oConn.Open "Filedsn=\somepath\mydb.dsn" & _
"Uid=admin;" & _
"Pwd=;"
Iii. ODBC dsn-less Connections
A) ODBC Text Driver
oConn.Open _
"Driver={microsoft Text Driver (*.txt; *.csv)}; "& _
"Dbq=\somepath\;" & _
"Extensions=asc,csv,tab,txt;" & _
"Persist Security Info=false"
Note: You need to specify the file name to use in the SQL statement. For example:
oRS.Open "Select * from Customer.csv", _
Oconn, adOpenStatic, adLockReadOnly, adCmdText
b) ODBC Driver for Access
i) General safety mode:
oConn.Open _
"Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=\somepath\mydb.mdb;" & _
"Uid=admin;" & _
"Pwd=;"
II) If the system database is used:
oConn.Open _
"Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=\somepath\mydb.mdb;" & _
"SYSTEMDB=\SOMEPATH\MYDB.MDW;", _
"Admin", "" "
c) ODBC Driver for SQL Server
i) General safety mode
oConn.Open "Driver={sql Server};" & _
"SERVER=CARL2;" & _
"Database=pubs;" & _
"UID=SA;" & _
"Pwd=;"
II) using Trust security mode:
oConn.Open "Driver={sql Server};" & _
"SERVER=CARL2;" & _
"Database=pubs;" & _
"Uid=;" & _
"Pwd=;"
Note: To use the blank UID and pwd
d) ODBC Driver for Oracle
i) Use the existing Oracle ODBC Driver from Microsoft:
oConn.Open _
"Driver={microsoft ODBC for Oracle};" & _
"Server=oracleserver.world;" & _
"Uid=demo;" & _
"Pwd=demo;"
II Use the older version of Oracle ODBC Driver from Microsoft:
oConn.Open _
"Driver={microsoft ODBC Driver for Oracle};" & _
"Connectstring=oracleserver.world;" & _
"Uid=demo;" & _
"Pwd=demo;"
IIII) using Microsoft OLE DB data link connections Way Data link File (UDL)
a) using absolute paths
oConn.Open "File name=\somepath\pubs.udl;"
b) using relative paths
oConn.Open "File name=pubs.udl;"
V) OLE DB Provider connections mode
A) OLE DB Provider for ODBC Databases
i) Access (Jet):
oConn.Open _
"Provider=msdasql;" & _
"Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=\somepath\mydb.mdb;" & _
"Uid=admin;" & _
"Pwd=;"
II) SQL Server:
oConn.Open _
"Provider=msdasql;" & _
"Driver={sql Server};" & _
"SERVER=CARL2;" & _
"Database=pubs;" & _
"UID=SA;" & _
"Pwd=;"
b) OLE DB Provider for Microsoft Jet (Access)
i) General safety mode:
oConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\somepath\mydb.mdb;" & _
"User id=admin;" & _
"Password=;"
II) If the system database is used:
oConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\somepath\mydb.mdb;" & _
"Jet Oledb:system database=system.mdw;", _
"Admin", "" "
Note: When using the OLE DB Provider4.0 version, you need to convert the MDB and MDW files into a 4.0 database format
III) If the MDB requires a database password:
oConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\somepath\mydb.mdb;" & _
"Jet oledb:database Password=mydbpassword;", _
"Admin", "" "
c) OLE DB Provider for EXCEL spreadsheet:
oConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\somepath\expenses.xls;" & _
"Extended properties=" "Excel 8.0; Hdr=yes; ""; "
Note: "Hdr=yes" means row headings in the first row, and the first row will not be included in the recordset in provider
d) OLE DB Provider for SQL Server
i) General safety mode:
oConn.Open "Provider=sqloledb" & _
"Network LIBRARY=DBMSSOCN;" & _
"Data Source=carl2;" & _
"Initial catalog=pubs;" & _
"User Id=sa;" & _
"Password=;"
II) using Trust security mode:
oConn.Open "Provider=sqloledb" & _
Network LIBRARY=DBMSSOCN; "& _
"Data Source=carl2;" & _
"Initial catalog=pubs;" & _
"Trusted_connection=yes;"
Note: "Network LIBRARY=DBMSSOCN" declares that OLE DB replaces named pipes with TCP/IP.
e) OLE DB Provider for Oracle
oConn.Open "Provider=msdaora" & _
"Data Source=oracleserver.world;" & _
"User Id=sa;" & _
"Password=;"
(VI) Remote OLE DB Provider connections (that's the way I've been researching RDS. ):
A) MS remote-access (Jet)
i) ODBC DSN:
oConn.Open "Remote server=http://carl2;" & _
"Remote Provider=msdasql;" & _
"Dsn=advworks;" & _
"Uid=admin" & _
"Pwd=;"
II) OLE DB Provider:
oConn.Open "Provider=ms Remote;" & _
"Remote Server=http://carl2;" & _
"Remote provider=microsoft.jet.oledb.4.0;" & _
"Data Source=\somepath\mydb.mdb;", _
"Admin", "" "
III) OLE DB provider Custom Transaction Object
oConn.Open "Provider=ms Remote;" & _
"Remote Server=http://carl2;" & _
"Handler=msdfmap. Handler; "& _
"Data Source=myadvworksoledbconnecttag;"
b) MS Remote-sql Server
i) ODBC DSN:
oConn.Open "Remote server=http://carl2;" & _
"Remote Provider=msdasql;" & _
"Network LIBRARY=DBMSSOCN;" & _
"Dsn=pubs;" & _
"Uid=sa" & _
"Pwd=;"
II) OLE DB Provider
oConn.Open "Provider=ms Remote;" & _
"Remote Server=http://carl2;" & _
"Remote provider=sqloledb;" & _
"Network LIBRARY=DBMSSOCN;" & _
"Data Source=carl2;" & _
"Initial catalog=pubs;" & _
"User Id=sa;" & _
"Password=;"



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.