这样吧...
Private Function ConnectToDatabase() As Boolean
On Error GoTo ErrHandler
Dim Conn As ADODB.Connection, DBName As String, ServerAdd As String, UserName As String, UserPwd As String
UserName = "sa"
UserPwd = ""
DBName = "数据库名"
ServerAdd = "服务器IP"
Conn.ConnectionTimeout = 10
Conn.CursorLocation = adUseClient
Conn.ConnectionString = "uid=" & UserName & ";pwd=" & UserPwd & ";driver={SQL SERVER};server=" & ServerAdd & ";database=" & DBName & ";dsn=''"
Conn.Open
ConnectToDatabase = True
Exit Function
ErrHandler:
MsgBox "错误信息:" & Err.Description, vbCritical, "警告"
Exit Function
End Function