vb 连接 sql server08 显示无效的授权说明,求高手帮忙啊
我的sql-server 是windows 身份验证,没有设密码,vb的代码如下,麻烦高手看下
Option Explicit
Dim objconn As New ADODB.Connection
Dim sqlstring As String
Dim connstring As String
Dim objrs As New ADODB.Recordset
Private Sub showdata(rs As ADODB.Recordset, dgrid As MSFlexGrid)
Dim rownum As Integer
rownum = 1
dgrid.Rows = rownum
dgrid.Cols = rs.Fields.Count - 3
For j = 0 To rs.Fields.Count - 1 - 3
dgrid.TextMatrix(0, j) = rs.Fields(j).Name
Next j
Do While Not rs.EOF
rownum = rownum + 1
dgrid.Rows = rownum
For j = 0 To rs.Fields.Count - 1 - 3
If Not IsNull(rs.Fields(j).Value) Then
dgrid.TextMatrix(rownum - 1, j) = rs.Fields(j).Value
End If
Next j
rs.MoveNext
Loop
End Sub
Private Sub form_load()
connstring = "provider=sqloledb.1"
connstring = connstring & "initial catalog=p-pc; data source=a
building"
With objconn
.ConnectionString = conntring
.ConnectionTimeout = 10
.Open
End With
End Sub
Private Sub command1_click()
objrs.Open "set1", objconn, adOpenDynamic, adCmdTable
Call showdata(objrs, MSFlexGrid1)
End Sub
Private Sub command2_click()
objrs.Close: Set objrs = Nothing
objrs.Close: Set objconn = Nothing
End
End Sub
[解决办法]
不要用WIN的身份验证,自己设数据库账户密码然后用ADODC控件生成连接串试试?
[解决办法]
'这样试试
with objconn
If .State = adStateOpen Then .Close
.ConnectionString = "driver=SQL Server;server=SQL实例名;uid=SA;pwd=SA的密码;database=数据库名"
.CommandTimeout = 0
.Open
End With