|
8#
楼主 |
发表于 2005-7-30 05:15:00
|
只看该作者
我的连接数据库代码是:Private Sub test_Click()
'数据库连接
Dim Server As String
Dim userid As String
Dim PassWord As String
Dim Catalog As String
On Error Resume Next
Server = Trim(DLookup("[Server]", "TB_Server"))
userid = Trim(DLookup("[UserId]", "TB_Server"))
PassWord = Trim(DLookup("[PassWord]", "TB_Server"))
Catalog = Trim(DLookup("[Catalog]", "TB_Server"))
'MsgBox Server
Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection
Conn.ConnectionString = "rovider='SQLOLEDB';Data Source='" & Server & "';" & _
"Initial Catalog='" & Catalog & "';Integrated Security='SSPI';User Id='" & userid & "'assword='" & PassWord & "'"
Conn.open
MsgBox GetState(Conn.State), vbOKOnly + vbInformation, "连接状态:"
End SubPublic Function GetState(intState As Integer) As String
Select Case intState
Case adStateClosed
GetState = "未能成功与数据库建立连接,请重试或与管理员联系!"
Case adStateOpen
GetState = "已与数据库成功连接!"
End SelectEnd Function其中TB_Server是存放IP、User ID 、PassWord、数据库等信息的我已经搞了一天,还是连不上数据库服务器,但是连本机就一切正常。
|
|