常用ADO连接数据库字符串大全文档格式.docx
《常用ADO连接数据库字符串大全文档格式.docx》由会员分享,可在线阅读,更多相关《常用ADO连接数据库字符串大全文档格式.docx(18页珍藏版)》请在冰豆网上搜索。
ODBCDriverforExcel
ODBCDriverforMySQL
ODBCDriverforOracle
ODBCDriverforParadox
ODBCDriverforSQLServer
ODBCDriverforSybase
ODBCDriverforSybaseSQLAnywhere
ODBCDriverforText
ODBCDriverforTeradata
ODBCDriverforVisualFoxPro
OLEDBDataLinkConnectionsDataLinkFile(UDL)
OLEDBDataProviderConnections OLEDBProviderforAS/400
OLEDBProviderforActiveDirectoryService
OLEDBProviderforDB2
OLDDBProviderforInternetPublishing
OLEDBProviderforIndexServer
OLEDBProviderforMicrosoftJet
OLEDBProviderforODBCDatabases
OLEDBProviderforOracle(FromMicrosoft)
OLEDBProviderforOracle(FromOracle)
OLEDBProviderforSimpleProvider
OLEDBProviderforSQLServer
RemoteDataService(RDS)ConnectionsRDSDataControl-ConnectProperty
RDSDataControl-URLProperty
ADOURLConnectionsADORecordset
MSRemoteProviderConnectionsMSRemote-Access(Jet)
MSRemote-SQLServer
DataShapeProviderConnections MSDataShape-SQLServer
.NETManagedProviderConnectionsSQLClient.NETManagedProvider(System.Data.SqlClient)
OLEDB.NETManagedProvider(System.Data.OleDb)
ODBC.NETManagedProvider(System.Data.ODBC)
ODBCDSNConnections
UsinganODBCDSN(DataSourceName)isatwostepprocess.
1)YoumustfirstcreatetheDSNviathe"
ODBCDataSourceAdministrator"
program
foundinyourcomputer'
sControlPanel(orAdministrativeToolsmenuinWindows2000).
MakesuretocreateaSYSTEMDSN(notaUSERDSN)whenusingASP.
Note:
YoucanalsocreatetheDSNviaVBcode.
2)Thenusethefollowingconnectionstring-withyourownDSNnameofcourse. ;
-)
ODBC-DSN
oConn.Open"
DSN=AdvWorks;
"
&
_
"
Uid=Admin;
Pwd=;
YoucanalsocreateanduseaFileDSN.ThenusethefollowingADOConnectionstring:
ODBC-FileDSN
FILEDSN=c:
\somepath\mydb.dsn;
Formoreinformation,see:
AboutODBCdatasourcesand
HowtoUseFileDSNsandDSN-lessConnections
TheproblemwithDSNisthatUserscan(andwill)modifythem(ordeletebymistake),
thenyourprogramwon'
tworksowell...Soit'
sbettertouseaDSN-LessorOLEDBProvider
connectionstringwithaTrustedConnectionifpossible!
ODBCDSN-LessConnections
ODBCDriverforAS/400
Driver={ClientAccessODBCDriver(32-bit)};
System=myAS400;
Uid=myUsername;
Pwd=myPassword;
AFastPathtoAS/400Client/Server
ForStandardSecurity:
Driver={MicrosoftAccessDriver(*.mdb)};
Dbq=c:
\somepath\mydb.mdb;
IfyouareusingaWorkgroup(Systemdatabase):
SystemDB=c:
\somepath\mydb.mdw;
_
admin"
"
IfMDBislocatedonanetworkshare:
Dbq=\\myServer\myShare\myPath\myDb.mdb;
MicrosoftAccessDriverProgrammingConsiderations
Driver={MicrosoftdBASEDriver(*.dbf)};
"
DriverID=277;
\somepath;
SpecifythefilenameintheSQLstatement.Forexample:
oRs.Open"
Select*Fromuser.dbf"
oConn,,,adCmdText
MDAC2.1(orgreater)requirestheBorlandDatabaseEngine(BDE)toupdatedBaseDBFfiles.(Q238431).
dBASEDriverProgrammingConsiderations
Driver={MicrosoftExcelDriver(*.xls)};
DriverId=790;
\somepath\mySpreadsheet.xls;
DefaultDir=c:
MicrosoftExcelDriverProgrammingConsiderations
ODBCDriverforMySQL(viaMyODBC)
Toconnecttoalocaldatabase
Driver={mySQL};
Server=MyServerName;
Option=16834;
Database=mydb;
Toconnecttoaremotedatabase
Server=;
Port=3306;
Option=131072;
Stmt=;
ProgramsKnowntoWorkwithMyODBC
ForthecurrentOracleODBCDriverfromMicrosoft:
Driver={MicrosoftODBCforOracle};
Server=OracleServer.world;
FortheolderOracleODBCDriverfromMicrosoft:
Driver={MicrosoftODBCDriverforOracle};
ConnectString=OracleServer.world;
ConnectionStringFormatandAttributes
Driver={MicrosoftParadoxDriver(*.db)};
DriverID=538;
Fil=Paradox5.X;
\dbpath\;
CollatingSequence=ASCII;
MDAC2.1(orgreater)requirestheBorlandDatabaseEngine(BDE)toupdateParadoxISAMfDBFfiles.(Q230126).
ParadoxDriverProgrammingConsiderations
Driver={SQLServer};
"
Database=myDatabaseName;
"
ForTrustedConnectionsecurity:
Uid=;
'
or
Trusted_Connection=yes;
ToPromptuserforusernameandpassword
oConn.Properties("
Prompt"
)=adPromptAlways
DataBase=myDatabaseName;
SQLDriverConnect(ODBC)
IfusingtheSybaseSystem11ODBCDriver:
Driver={SYBASESYSTEM11};
Srvr=myServerName;
IfusingtheIntersolv3.10SybaseODBCDriver:
Driver={INTERSOLV3.1032-BITSybase};
SybaseSystem10ODBCDriverReferenceGuide
ODBC;
Driver=SybaseSQLAnywhere5.0;
Dbf=c:
\sqlany50\mydb.db;
Dsn="
;
IncludingtheDSNtagwithanullstringisabsolutelycriticalorelseyougetthedreaded-7778error.
SybaseSQLAnywhereUserGuide
Provider=Teradata;
DBCName=MyDbcName;
Database=MyDatabaseName;
Formoreinformation,seeTeradataODBCDriver
Driver={MicrosoftTextDriver(*.txt;
*.csv)};
\somepath\;
Extensions=asc,csv,tab,txt;
PersistSecurityInfo=False"
oRs.Open"
Select*Fromcustomer.csv"
oConn,adOpenStatic,adLockReadOnly,adCmdText
TextFileDriverProgrammingConsiderations
Withadatabasecontainer:
Driver={MicrosoftVisualFoxProDriver};
SourceType=DBC;
SourceDB=c:
\somepath\mySourceDb.dbc;
Exclusive=No;
Withoutadatabasecontainer(FreeTableDirectory):
SourceType=DBF;
\somepath\mySourceDbFolder;
VisualFoxProODBCDriverandQ165492
OLEDBDataLinkConnections
DataLinkFile(UDL)
ForAbsolutePath:
FileName=c:
\somepath\myDatabaseName.udl;
ForRelativePath:
FileName=myDatabaseName.udl;
HOWTO:
UseDataLinkFileswithADO
Windows2000nolongercontainsthe"
New|MicrosoftDataLink"
menu
anymore.YoucanaddtheDataLinkmenubackinthemenulistbyrunningthe
C:
\ProgramFiles\CommonFiles\System\OleDB\newudl.reg"
regfile,
thenright-clickonthedesktopandselect"
menu.
OryoucanalsocreateaDataLinkfilebycreatingatextfileandchangeit'
s
fileextensionto"
.udl"
thendouble-clickthefile.
OLEDBProviderConnections
OLEDBProviderforAS/400
Provider=IBMDA400;
Datasource=myAS400;
UserId=myUsername;