中国从日本进口什么:vb数据库连接(用sa用户名登录,但登录方式报错)急!!!!

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/09 03:51:28
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"
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
我是用SQL身份证登录的密码为空,但还是出现登录方式出错,不知代码哪里有问题

安装MSSQL的时候要注意登陆验证方式的选择,如果你选择的只验证Windows用户的话,那么你用SA是不能登陆的