返回首页
当前位置: 主页 > Excel教程 > Excel VBA教程 >

ADO连接数据库字符串大全(VP,Excel,文本,Sybase,.NET等)(2)

时间:2012-06-17 02:06来源:Office教程学习网 www.office68.com编辑:麦田守望者


ODBC Driver for SQL Server
 
For Standard Security:

oConn.Open "Driver={SQL Server};" & _
          "Server=MyServerName;" & _
         "Database=myDatabaseName;" & _
         "Uid=myUsername;" & _
          "Pwd=myPassword;"

For Trusted Connection security:

oConn.Open "Driver={SQL Server};" & _
          "Server=MyServerName;" & _
          "Database=myDatabaseName;" & _
          "Uid=;" & _
          "Pwd=;"

' or

oConn.Open "Driver={SQL Server};" & _
          "Server=MyServerName;" & _
          "Database=myDatabaseName;" & _
          "Trusted_Connection=yes;"

To Prompt user for username and password

oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Driver={SQL Server};" & _
          "Server=MyServerName;" & _
          "DataBase=myDatabaseName;"
  

For more information, see: SQLDriverConnect (ODBC)


ODBC Driver for Sybase
 
If using the Sybase System 11 ODBC Driver:

oConn.Open "Driver={SYBASE SYSTEM 11};" & _
          "Srvr=myServerName;" & _
         "Uid=myUsername;" & _
          "Pwd=myPassword;"

If using the Intersolv 3.10 Sybase ODBC Driver:

oConn.Open "Driver={INTERSOLV 3.10 32-BIT Sybase};" & _
          "Srvr=myServerName;" & _
         "Uid=myUsername;" & _
          "Pwd=myPassword;"

For more information, see: Sybase System 10 ODBC Driver Reference Guide


ODBC Driver for Sybase SQL Anywhere
 
oConn.Open "ODBC; Driver=Sybase SQL Anywhere 5.0;" & _
          "DefaultDir=c:\dbpath\;" & _
          "Dbf=c:\sqlany50\mydb.db;" & _
         "Uid=myUsername;" & _
          "Pwd=myPassword;"
          "Dsn="""";"

Note: Including the DSN tag with a null string is absolutely critical or else you get the dreaded -7778 error.

For more information, see: Sybase SQL Anywhere User Guide


ODBC Driver for Teradata
 
oConn.Open "Provider=Teradata;" & _
          "DBCName=MyDbcName;" & _
          "Database=MyDatabaseName;" & _
          "Uid=myUsername;" & _
          "Pwd=myPassword;"

For more information, see Teradata ODBC Driver


ODBC Driver for Text
 
oConn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
          "Dbq=c:\somepath\;" & _
          "Extensions=asc,csv,tab,txt;" & _
          "Persist Security Info=False"

Note: Specify the filename in the SQL statement. For example:

oRs.Open "Select * From customer.csv", _
        oConn, adOpenStatic, adLockReadOnly, adCmdText


For more information, see: Text File Driver Programming Considerations


ODBC Driver for Visual FoxPro
 
With a database container:

oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
          "SourceType=DBC;" & _
          "SourceDB=c:\somepath\mySourceDb.dbc;" & _
          "Exclusive=No;"

Without a database container (Free Table Directory):

oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
          "SourceType=DBF;" & _
          "SourceDB=c:\somepath\mySourceDbFolder;" & _
          "Exclusive=No;"


For more information, see: Visual FoxPro ODBC Driver and Q165492

 

OLE DB Data Link Connections
Data Link File (UDL)
 
For Absolute Path:

oConn.Open "File Name=c:\somepath\myDatabaseName.udl;"

For Relative Path:

oConn.Open "File Name=myDatabaseName.udl;"
 

For more information, see: HOWTO: Use Data Link Files with ADO

Note: Windows 2000 no longer contains the "New | Microsoft Data Link" menu 
anymore. You can add the Data Link menu back in the menu list by running the
"C:\Program Files\Common Files\System\Ole DB\newudl.reg" reg file,
then right-click on the desktop and select "New | Microsoft Data Link" menu. 
Or you can also create a Data Link file by creating a text file and change it's
file extension to ".udl", then double-click the file.

 

OLE DB Provider Connections
OLE DB Provider for AS/400
 
oConn.Open "Provider=IBMDA400;" & _
          "Data source=myAS400;"
          "User Id=myUsername;" & _
          "Password=myPassword;"

For more information, see:  A Fast Path to AS/400 Client/Server


OLE DB Provider for Active Directory Service
 
oConn.Open "Provider=ADSDSOObject;" & _
          "User Id=myUsername;" & _
          "Password=myPassword;"
 

For more information, see: Microsoft OLE DB Provider for Microsoft Active Directory Service


OLE DB Provider for DB2
 
oConn.Open = "Provider=DB2OLEDB;" &
           "Network Transport Library=TCPIP;" &
           "Network Address=MyServer;" & _
           "Package Collection=MyPackage;" &
           "Host CCSID=1142"
           "Initial Catalog=MyDB;" &
           "User ID=MyUsername;" & _
           "Password=MyPassword;"

For more information, see: OLE DB Provider for DB2
and INF: Configuring Data Sources for the Microsoft OLE DB Provider for DB2


OLE DB Provider for Index Server
 
oConn.Open "Provider=msidxs;" & _
          "Data source=MyCatalog;"
 

For more information, see: Microsoft OLE DB Provider for Microsoft Indexing Service


OLE DB Provider for Internet Publishing
 
oConn.Open "Provider=MSDAIPP.DSO;" & _
      "Data Source=http://mywebsite/myDir;" & _
      "User Id=myUsername;" & _
      "Password=myPassword;"
 

For more information, see: Microsoft OLE DB Provider for Internet Publishing and Q245359


OLE DB Provider for Microsoft Jet
 
For standard security:

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=c:\somepath\myDb.mdb;" & _
          "User Id=admin;" & _
          "Password=;"

If using a Workgroup (System Database):

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=c:\somepath\mydb.mdb;" & _

------分隔线----------------------------
标签(Tag):excel excel2007 excel2010 excel2003 excel技巧 excel教程 excel实例教程 excel2010技巧
------分隔线----------------------------
推荐内容
猜你感兴趣