Connection database Query Manual

Source: Internet
Author: User
Tags manual dsn odbc ole query safety mode
Connect to the database 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=somepathmydb.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=somepathmydb.mdb;" & _
"Uid=admin;" & _
"Pwd=;"
II) If the system database is used:
oConn.Open _
"Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=somepathmydb.mdb;" & _
"SYSTEMDB=SOMEPATHMYDB.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=somepathpubs.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=somepathmydb.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=somepathmydb.mdb;" & _
"User id=admin;" & _
"Password=;"
II) If the system database is used:
oConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=somepathmydb.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=SOMEPATHMYDB.M



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.