小米官网帐号不存在:vb数据库连接(问题)

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 05:03:35
我的sql现在无法用sa用户名登录,只能用windows登录,但在vb中执行sql就会出错,应该怎样才能恢复sa用户名登录,不能恢复的话怎样才能在windows登录,vb语句:
Option Explicit
Public conn As New ADODB.Connection '连接数据库方式
Public rs As New ADODB.Recordset '数据库结果集
Public strSQL As String

Public Function ConnectToDB() As Boolean '连接数据库函数
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=pubs\t04"
conn.ConnectionTimeout = 10
conn.Open
If conn.State = 1 Then
ConnectToDB = True
Else
ConnectToDB = False
End If

End Function

Public Sub DisConnect() '关闭连接
If conn.State = 1 Then
conn.Close
End If
End Sub

Public Function Login(strUser As String, strPWD As String) As Boolean
strSQL = "select count(*) as cnt from login where userid='" & strUser & "' and pwd='" & strPWD & "'"
Login = False
If ConnectToDB = True Then '执行是否连接
If ExecuteSQL(strSQL) Then '执行sql语句命令
If rs!cnt = 1 Then '执行结果(用户名与密码是否正确)
MsgBox "登录成功"
Login = True
Else
MsgBox "用户名或密码错误!"
End If
End If
Else
MsgBox "连接数据库失败"
End If
End Function

Public Function ExecuteSQL(strSQL As String) As Boolean
On Error Resume Next
Set rs = conn.Execute(strSQL)
If Err.Number <> 0 Then
ExecuteSQL = False
MsgBox "执行SQL语句出错" 'Err.Description
Err.Clear
Else
ExecuteSQL = True
End If
End Function

数据库登陆方式改为混和方式,然后设置sa的密码就可以了