If DbConnection.State = adStateOpen And Not IsEmpty(adStateOpen) Then DbConnection.Close End If ConnStr = "Provider=MSDASQL.1;Persist Security Info=False;DRIVER=" & DriveName(DbType) & ";" & UserPwd(DbType) & "DBQ=" & FilePath DbConnection.ConnectionString = ConnStr DbConnection.Open DoEvents
If Err.Number = 0 Then DbStyle = tDbType(DbType) CreateOtherConn = True Else Err.Clear DbStyle = "" CreateOtherConn = False End If End Function
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;"------------------------------------------------ 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.
用ADO连 dim cnn as new adodb.connection dim rst as new adodb.recordset cnn.connectionstring="driver{SQL 6.5};uid=sa;pwd=;database=db_name;" cnn.cursorlocation=aduseclient cnn.open
'数据库类型.
Public Enum SmDbType
Access = 1 'Access
Excel = 2 'Excel
Text = 3 '文本
FoxPro = 4 'FoxPro
dBase = 5 'dBase
SYBASE = 6 'DB
End Enum
'
'创建一个连接(连接到其它数据库类型)
'函数名:CreateOtherConn
'参数: DbConnection ADODB连接,FilePath 数据库路径,UserName 登录用户名,PassWord 登录密码,DbType SmDbType枚举数据库类型
'返回值:TRUE 连接成功.FALSE 连接失败.
'例:
'CreateOtherConn Cnn, "E:\CjhLx\dbf", , , FoxPro
'StrSql = "select * from [employee.dbf]"
'Set Rs = RsOpen(Cnn, StrSql)
'Set DataGrid1.DataSource = RsPublic Function CreateOtherConn(ByRef DbConnection As ADODB.Connection, _
FilePath As String, _
Optional UserName As String = "admin", _
Optional PassWord As String = "", _
Optional DbType As SmDbType = Access) As Boolean
Dim ConnStr As String
Dim DriveName(5) As String
Dim tDbType(5) As String
Dim UserPwd(5) As String
'驱动程序
DriveName(1) = "{Microsoft Access Driver (*.mdb)}"
DriveName(2) = "{Microsoft Excel Driver (*.xls)}"
DriveName(3) = "{Microsoft Text Driver (*.txt; *.csv)}"
DriveName(4) = "{Microsoft Visual FoxPro Driver};SourceType=DBF"
DriveName(5) = "{Microsoft dBase Driver (*.dbf)}"
DriveName(6) = "{Microsoft Paradox-Treiber (*.db )}"
'{Microsoft Paradox Driver (*.db )}
'类型
tDbType(1) = "MDB"
tDbType(2) = "XLS"
tDbType(3) = "TXT"
tDbType(4) = "FDB"
tDbType(5) = "DDB"
tDbType(6) = "DB"
'用户名和密码.
UserPwd(1) = "Uid=" & UserName & ";Pwd=" & PassWord & ";"
UserPwd(2) = "Uid=" & UserName & ";Pwd=" & PassWord & ";"
UserPwd(3) = ""
UserPwd(4) = "Uid=" & UserName & ";Pwd=" & PassWord & ";"
UserPwd(5) = "Uid=" & UserName & ";Pwd=" & PassWord & ";"
UserPwd(6) = "Uid=" & UserName & ";Pwd=" & PassWord & ";"
On Error Resume Next
If DbConnection.State = adStateOpen And Not IsEmpty(adStateOpen) Then
DbConnection.Close
End If
ConnStr = "Provider=MSDASQL.1;Persist Security Info=False;DRIVER=" & DriveName(DbType) & ";" & UserPwd(DbType) & "DBQ=" & FilePath
DbConnection.ConnectionString = ConnStr
DbConnection.Open
DoEvents
If Err.Number = 0 Then
DbStyle = tDbType(DbType)
CreateOtherConn = True
Else
Err.Clear
DbStyle = ""
CreateOtherConn = False
End If
End Function
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;"------------------------------------------------
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.
dim cnn as new adodb.connection
dim rst as new adodb.recordset cnn.connectionstring="driver{SQL 6.5};uid=sa;pwd=;database=db_name;"
cnn.cursorlocation=aduseclient
cnn.open