请问VB怎么连接SQL数据库?
我想一运行VB就打开数据库,所以在主函数里连接
这是在新添加的模块里写的,可是运行不了?在第三行出错,我不知道为什么?第一,第二行是什么意思我不是很明白,请教教我!我真的好急。
Public Const LOG_DEBUG As String = "DEBUGS"
Public Const LOG_ERROR As String = "ErrorS"
Public Conn As New ADODB.Connection
Public Sub Main()
On Error GoTo ErrorHandler
initialize_log
t_log.log_open
Set Conn = New ADODB.Connection
' 用ODBC DSN 建立连接
Conn.ConnectionString = "driver={SQL Server};server=YU-TSUOL27GB26S;" & _
"UID=;PWD=;Database=KinderGarten"
' Conn.ConnectionString = "driver={SQL Server};server=F19;" & _
"UID=;PWD=;Database=KinderGarten"
Conn.Open
Call diet_select
Call t_log.log_write(Format(Date, "YYYYMMDD") & " " & Format(Time, "HH:MM:SS"), " open KinderGarten success !")
Exit Sub
ErrorHandler:
Call t_log.log_write(LOG_ERROR, Err.Description)
End Sub
Public Sub initialize_log()
Set t_log = New Log
End Sub
End Sub