📄 ado连接数据库字符串大全(vp,excel,文本,sybase,.net等).htm
字号:
Driver=Sybase SQL Anywhere 5.0;" & _<BR>
"DefaultDir=c:\dbpath\;" & _<BR>
"Dbf=c:\sqlany50\mydb.db;" & _<BR> "Uid=myUsername;"
& _<BR> "Pwd=myPassword;"<BR>
"Dsn="""";"</P>
<P>Note: Including the DSN tag with a null string is absolutely
critical or else you get the dreaded -7778 error.</P>
<P>For more information, see: Sybase SQL Anywhere User Guide</P>
<P></P>
<P>ODBC Driver for Teradata <BR> <BR>oConn.Open
"Provider=Teradata;" & _<BR> "DBCName=MyDbcName;"
& _ <BR> "Database=MyDatabaseName;" & _
<BR> "Uid=myUsername;" & _<BR>
"Pwd=myPassword;"</P>
<P>For more information, see Teradata ODBC Driver</P>
<P></P>
<P>ODBC Driver for Text <BR> <BR>oConn.Open "Driver={Microsoft
Text Driver (*.txt; *.csv)};" & _<BR>
"Dbq=c:\somepath\;" & _<BR>
"Extensions=asc,csv,tab,txt;" & _<BR> "Persist
Security Info=False"</P>
<P>Note: Specify the filename in the SQL statement. For
example:</P>
<P>oRs.Open "Select * From customer.csv", _<BR> oConn,
adOpenStatic, adLockReadOnly, adCmdText</P>
<P><BR>For more information, see: Text File Driver Programming
Considerations</P>
<P></P>
<P>ODBC Driver for Visual FoxPro <BR> <BR>With a database
container:</P>
<P>oConn.Open "Driver={Microsoft Visual FoxPro Driver};" &
_<BR> "SourceType=DBC;" & _<BR>
"SourceDB=c:\somepath\mySourceDb.dbc;" & _<BR>
"Exclusive=No;" </P>
<P>Without a database container (Free Table Directory):</P>
<P>oConn.Open "Driver={Microsoft Visual FoxPro Driver};" &
_<BR> "SourceType=DBF;" & _<BR>
"SourceDB=c:\somepath\mySourceDbFolder;" & _<BR>
"Exclusive=No;" <BR></P>
<P>For more information, see: Visual FoxPro ODBC Driver and
Q165492</P>
<P><BR></P>
<P>OLE DB Data Link Connections<BR>Data Link File (UDL) <BR>
<BR>For Absolute Path:</P>
<P>oConn.Open "File Name=c:\somepath\myDatabaseName.udl;" </P>
<P>For Relative Path:</P>
<P>oConn.Open "File Name=myDatabaseName.udl;"<BR> </P>
<P>For more information, see: HOWTO: Use Data Link Files with
ADO</P>
<P>Note: Windows 2000 no longer contains the "New | Microsoft Data
Link" menu <BR>anymore. You can add the Data Link menu back in the
menu list by running the <BR>"C:\Program Files\Common
Files\System\Ole DB\newudl.reg" reg file, <BR>then right-click on
the desktop and select "New | Microsoft Data Link" menu. <BR>Or
you can also create a Data Link file by creating a text file and
change it's <BR>file extension to ".udl", then double-click the
file.</P>
<P><BR></P>
<P>OLE DB Provider Connections<BR>OLE DB Provider for AS/400 <BR>
<BR>oConn.Open "Provider=IBMDA400;" & _<BR> "Data
source=myAS400;"<BR> "User Id=myUsername;" &
_<BR> "Password=myPassword;"</P>
<P>For more information, see: A Fast Path to AS/400
Client/Server</P>
<P></P>
<P>OLE DB Provider for Active Directory Service <BR>
<BR>oConn.Open "Provider=ADSDSOObject;" & _<BR> "User
Id=myUsername;" & _<BR> "Password=myPassword;"<BR>
</P>
<P>For more information, see: Microsoft OLE DB Provider for
Microsoft Active Directory Service</P>
<P></P>
<P>OLE DB Provider for DB2 <BR> <BR>oConn.Open =
"Provider=DB2OLEDB;" & <BR> "Network Transport
Library=TCPIP;" & <BR> "Network Address=MyServer;"
& _<BR> "Package Collection=MyPackage;" &
<BR> "Host CCSID=1142"<BR> "Initial
Catalog=MyDB;" & <BR> "User ID=MyUsername;" &
_<BR> "Password=MyPassword;"</P>
<P>For more information, see: OLE DB Provider for DB2 <BR>and INF:
Configuring Data Sources for the Microsoft OLE DB Provider for DB2
</P>
<P></P>
<P>OLE DB Provider for Index Server <BR> <BR>oConn.Open
"Provider=msidxs;" & _<BR> "Data
source=MyCatalog;"<BR> </P>
<P>For more information, see: Microsoft OLE DB Provider for
Microsoft Indexing Service</P>
<P></P>
<P>OLE DB Provider for Internet Publishing <BR> <BR>oConn.Open
"Provider=MSDAIPP.DSO;" & _<BR> "Data
Source=http://mywebsite/myDir;" & _ <BR> "User
Id=myUsername;" & _<BR> "Password=myPassword;" <BR> </P>
<P>For more information, see: Microsoft OLE DB Provider for
Internet Publishing and Q245359</P>
<P></P>
<P>OLE DB Provider for Microsoft Jet <BR> <BR>For standard
security:</P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &
_<BR> "Data Source=c:\somepath\myDb.mdb;" & _
<BR> "User Id=admin;" & _<BR>
"Password=;"</P>
<P>If using a Workgroup (System Database):</P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &
_<BR> "Data Source=c:\somepath\mydb.mdb;" & _
<BR> "Jet OLEDB:System Database=MySystem.mdw;",
_<BR> "admin", "" </P>
<P>Note, remember to convert both the MDB and the MDW to the 4.0
database format when using the 4.0 OLE DB Provider.</P>
<P>If MDB has a database password:</P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &
_<BR> "Data Source=c:\somepath\mydb.mdb;" & _
<BR> "Jet OLEDB:Database Password=MyDbPassword;",
_<BR> "admin", ""</P>
<P>If MDB is located on a network share:</P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &
_<BR> "Data
Source=\\myServer\myShare\myPath\myDb.mdb;</P>
<P>If want to open up the Access database exclusively:</P>
<P>oConn.Mode = adModeShareExclusive<BR>oConn.Open
"Provider=Microsoft.Jet.OLEDB.4.0;" & _<BR> "Data
Source=c:\somepath\myDb.mdb;" & _<BR> "User
Id=admin;" & _<BR> "Password=;"</P>
<P><BR>For more information, see: OLE DB Provider for Microsoft
Jet, Q191754, Q225048, Q239114, and Q271908</P>
<P></P>
<P>You can also open an Excel Spreadsheet using the "OLE DB
Provider for Microsoft Jet" </P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &
_<BR> "Data Source=c:\somepath\myExcelSpreadsheet.xls;"
& _<BR> "Extended Properties=""Excel 8.0;HDR=Yes;"";"
</P>
<P>Where "HDR=Yes" means that there is a header row in the cell
range <BR>(or named range), so the provider will not include the
first row of the<BR>selection into the recordset. If "HDR=No",
then the provider will include<BR>the first row of the cell range
(or named ranged) into the recordset. </P>
<P>For more information, see: Q278973<BR></P>
<P>You can also open a Text File using the "OLE DB Provider for
Microsoft Jet" </P>
<P>oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
<BR> "Data Source=c:\somepath\;" & _ <BR>
"Extended Properties=""text;HDR=Yes;FMT=Delimited;"";" <BR><BR>'
Then open a recordset based on a select on the actual
file<BR>oRs.Open "Select * From MyTextFile.txt", oConn,
adOpenStatic, adLockReadOnly, adCmdText </P>
<P>For more information, see: Q262537 </P>
<P></P>
<P>OLE DB Provider for ODBC Databases <BR> <BR>For Access
(Jet):</P>
<P>oConn.Open "Provider=MSDASQL;" & _ <BR>
"Driver={Microsoft Access Driver (*.mdb)};" & _<BR>
"Dbq=c:\somepath\mydb.mdb;" & _<BR> "Uid=myUsername;"
& _<BR> "Pwd=myPassword;"</P>
<P>For SQL Server:</P>
<P>oConn.Open "Provider=MSDASQL;" & _ <BR>
"Driver={SQL Server};" & _<BR> "Server=myServerName;"
& _<BR> "Database=myDatabaseName;" &
_<BR> "Uid=myUsername;" & _<BR>
"Pwd=myPassword;"</P>
<P>For more information, see: Microsoft OLE DB Provider for
ODBC</P>
<P></P>
<P>OLE DB Provider for Oracle (from Microsoft) <BR>
<BR>oConn.Open "Provider=msdaora;" & _<BR> "Data
Source=MyOracleDB;" & _ <BR> "User Id=myUsername;"
& _<BR> "Password=myPassword;"</P>
<P>For more information, see: Microsoft OLE DB Provider for
Oracle</P>
<P></P>
<P>OLE DB Provider for Oracle (from Oracle) <BR> <BR>For Standard
Security:</P>
<P>oConn.Open "Provider=OraOLEDB.Oracle;" & _<BR>
"Data Source=MyOracleDB;" & _ <BR> "User
Id=myUsername;" & _<BR> "Password=myPassword;"</P>
<P>For a Trusted Connection:</P>
<P>oConn.Open "Provider=OraOLEDB.Oracle;" & _<BR>
"Data Source=MyOracleDB;" & _ <BR> "User Id=/;" &
_<BR> "Password=;"<BR>' Or</P>
<P>oConn.Open "Provider=OraOLEDB.Oracle;" & _<BR>
"Data Source=MyOracleDB;" & _ <BR>
"OSAuthent=1;"<BR> </P>
<P>Note: "Data Source=" must be set to the appropriate Net8 name
which is known to the naming method in use. For example, for Local
Naming, it is the alias in the tnsnames.ora file; for Oracle
Names, it is the Net8 Service Name. </P>
<P>For more information, see: Connecting to an Oracle
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -