下面是登录窗口识别用户名和密码 
运行时显示"不可识别的数据库格式'这里是.mdf文件的路径'"错误,点调试就指向下面第九行"conn.open conectionstring" Option Explicit Public conn As New ADODB.Connection '标记连接对象 
Private Sub Form_Load() '系统初始化,加载数据库 
Dim Connectionstring As String 
Dim conn As New ADODB.Connection 
Connectionstring = "provider=Microsoft.Jet.oledb.4.0;" & _ 
"Data Source=" & App.Path & "\Student_Data.mdf" 
conn.Open Connectionstring 
End Sub Private Sub CommandButton1_Click() 
Dim SQL As String 
Dim rs_Login As New ADODB.Recordset 
If Trim(Text1.Text) = "" Then '判断输入的用户名是否为空 
MsgBox "请输入用户名", vbOKOnly + vbExclamation 
Text1.Text = "" 
txtuser.SetFocus 
ElseIf Text2.Text = "" Then 
MsgBox "请输入密码", vbOKOnly + vbExclamation 
Text2.Text = "" 
Text2.SetFocus 
Else 
SQL = "select * from basic_information where studentid='" & Text1.Text & "'" 
rs_Login.Open SQL, conn, adOpenKeyset, adLockPessimistic 
If rs_Login.EOF = True Then 
MsgBox "对不起,没有这个用户", vbOKOnly + vbExclamation 
Text1.Text = "" 
Text1.SetFocus 
rs_Login.Close 
Else '检验密码是否正确 
If rs_Login.Fields(1) = Text2.Text Then 
UserID = Text1.Text 
UserPow = rs_Login.Fields(2) 
rs_Login.Close 
Unload Me 
Main.Show 
Exit Sub 
Else 
MsgBox "密码错误,请您重输", vbOKOnly + vbExclamation 
Text1.Text = "" 
Text1.SetFocus 
rs_Login.Close 
End If 
End If 
End If 
End Sub 
Private Sub txtpwd_KeyPress(KeyAscii As Integer) '敲回车直接登陆 
If KeyAscii = 13 Then CommandButton1_Click 
End Sub

解决方案 »

  1.   

    不是,是sql server 2000 做的数据库,是不是连接出了问题啊,不能用那个连接啊
      

  2.   

    Connectionstring = "provider=msdasql;driver={sql server};server=yourserver;uid=yourloginname;pwd=password;database=databasename"
      

  3.   

    我在各位的帮助下,又作了修改,但还是有错误啊,指向rs_Login.Open SQL, conn, 1, 3 Option ExplicitPublic conn As New ADODB.Connection '标记连接对象
    Private Sub Form_Load() '系统初始化,加载数据库
    Dim Connectionstring As String, UID As String, PWD As String
    Dim conn As New ADODB.Connection
    conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"
    conn.Open
    End SubPrivate Sub CommandButton1_Click()
    Dim SQL As String
    Dim rs_Login As New ADODB.Recordset
    Dim UID As String, PWD As String
    If Trim(Text1.Text) = "" Then '判断输入的用户名是否为空
    MsgBox "请输入用户名", vbOKOnly + vbExclamation
    Text1.Text = ""
    Text1.SetFocus
    ElseIf Text2.Text = "" Then
    MsgBox "请输入密码", vbOKOnly + vbExclamation
    Text2.Text = ""
    Text2.SetFocus
    Else
    SQL = "select * from basic_information where studentid='" & Text1.Text & "'"
    rs_Login.Open SQL, conn, 1, 3 '调试错误指向这行,说连接无法执
    If rs_Login.EOF = True Then '此操作在上下文中可能被关闭或无效
    MsgBox "对不起,没有这个用户", vbOKOnly + vbExclamation
    Text1.Text = ""
    Text1.SetFocus
    rs_Login.Close
    Else '检验密码是否正确
    If rs_Login.Fields(1) = Text2.Text Then
    UID = Text1.Text
    PWD = rs_Login.Fields(2)
    rs_Login.Close
    Unload Me
    Main.Show
    Exit Sub
    Else
    MsgBox "密码错误,请您重输", vbOKOnly + vbExclamation
    Text1.Text = ""
    Text1.SetFocus
    rs_Login.Close
    End If
    End If
    End If
    End Sub
      

  4.   

    Connectionstring = "provider=msdasql;driver={sql server};server=yourserver;uid=yourloginname;pwd=password;database=databasename"uid、pwd是登陆Sql Server的登录登录帐户,不是你程序的
      

  5.   

    默认的user id = sa password ='你自已设定的' 数据库验证方式改为混合验证
      

  6.   

    默认的user id = sa password ='你自已设定的' 数据库验证方式改为混合验证
      

  7.   

    默认的user id = sa password ='你自已设定的' 数据库验证方式改为混合验证
      

  8.   

    我没设密码啊
    userid从哪看啊,谢谢
      

  9.   

    conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"
    ---------------------------------------------------------------------
    你用的是sql server2000数据库。
    数据库本身就用这个"sa"作为userid .
    -----------------------------
    你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
    ----
    如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
    ----------------------------------
    你再试一试
      

  10.   

    conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"
    ---------------------------------------------------------------------
    你用的是sql server2000数据库。
    数据库本身就用这个"sa"作为userid .
    -----------------------------
    你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
    ----
    如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
    ----------------------------------
    你再试一试
      

  11.   

    conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"
    ---------------------------------------------------------------------
    你用的是sql server2000数据库。
    数据库本身就用这个"sa"作为userid .
    -----------------------------
    你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
    ----
    如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
    ----------------------------------
    你再试一试
      

  12.   

    你数据库引擎不对,没有身份验证方式,你是不是用WINDOWS集成身份验证了?
      

  13.   

    conn.Connectionstring = "Provider=SQLOLEDB.1;Data Source=databaseServerName;User ID=sa;password = *****;Initial Catalog=databaseName ;"
      

  14.   

    conn.Connectionstring = "Provider=SQLOLEDB.1;Data Source=databaseServerName;User ID=sa;password = *****;Initial Catalog=databaseName ;"
      

  15.   

    conn.Connectionstring = "Provider=SQLOLEDB.1;Data Source=databaseServerName;User ID=sa;password = *****;Initial Catalog=databaseName ;"
      

  16.   

    mdf文件不能像MDB文件一样来用的!用SQL SERVER连接字符串
      

  17.   

    我用下面个运行的时候可以转到vb界面,但当我输入我输入我数据库中表的学号登录时就出错了指向rs_Login.Open SQL, conn, 1, 3这行,说是连接无效
    conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"如果我按楼上有的朋友说的把UID=改成UID=sa,一运行就直接说用户'sa'登录失败
    这是怎么回事啊?还有这个database后面是不是写我见的student数据库名字啊,谢谢各位的解答!!