在sql 2005的SQL Server Management Studio里面能保存数据吗?如果能,就是你程序的问题了.如果不能,看下面的内容.SQL Server 2005中,.mdf和.ldf文件附加,数据库成了只读的,该怎么解决?
1.打开 SQL Server Configuration Manager, 打开SQL Server SQLEXPRESS 的属性 2.在内置帐号处,把“网络服务”改成“本地系统”,重新启动SQL Server 2005 Express 后,再附加(Attach)数据库一切正常。 总结:之所以附加(Attach)上的数据库为“只读”,是因为启动SQL Server 的默认的启动帐号“网络服务”对所附加的数据库文件的权限不够造成的。 信息来源: 
http://hi.baidu.com/tsq_124/blog/item/76227f1fe25d8165f624e4a4.html

解决方案 »

  1.   

    这个是我从数据库提取信息的代码,怎样才能全部(关闭)清除内存占有,我的这段代码那个位置错了。
    可以运行但是数据库没有释放,怎样才能释放呢?
    Private Sub cmdok_Click()
    Dim fff As String
    Dim gs As String
    Set rs = CnNew.Execute("Select * From [jz] Where 帐号='" & Replace(txtUserName.Text, "'", "''") & "' And 密码='" & txtPassword.Text & "'")
    If Not rs.EOF Then '如果符合
    fff = rs("剩余时间")
    gs = rs("挂失")
    '关闭数据源
    rs.Close: Set rs = Nothing
    CnNew.Close: Set CnNew = Nothing
    If gs = 0 Then '没有挂失
    'Set gs = Nothing
    Randomize Timer
     Rnd (gs)
    If fff > 0 Then '剩余时间不为零
    '取消禁用任务管理器
    Close
    '取消禁用windows菜单
    If bswap Then
         SetParent win, task
         ShowWindow win, 1
    End If
    Open "C:\Program Files\swkz\zh.txt" For Output As #1
    Print #1, txtUserName.Text
    Close
    'Open "C:\Program Files\swkz\sj.txt" For Output As #1
    'Print #1, fff
    'Close
    Randomize Timer
     Rnd (fff)
    Shell "C:\Program Files\swkz\dl.exe", vbNormalFocus
    Call datalink.cloRs
    Call datalink.Clocn
    Unload Me '关闭现有窗体
    'MsgBox "登录成功"
    Else '如果不符合
    txtUserName.Text = ""
    txtPassword.Text = ""
    Label5.Caption = "登录失败!剩余时间为零!"
    End If
    Else '如果不符合
    txtUserName.Text = ""
    txtPassword.Text = ""
    Label5.Caption = "登录失败!帐号已经挂失!"
    End If
    Else
    txtUserName.Text = ""
    txtPassword.Text = ""
    Label5.Caption = "登录失败!用户名或密码错误!"
    'MsgBox "对不起,您的用户名密码不正确", vbCritical, "错误!"
    End If
    End Sub
    在标准模块中
    Public Sub Clocn()
    '闭关数据库
    On Error Resume Next
    If CnNew.State <> adStateClosed Then CnNew.Close
    Set CnNew = Nothing
    End SubPublic Sub cloRs()
    '闭关数据集
    On Error Resume Next
    If rs.State <> adStateClosed Then rs.Close
    Set rs = Nothing
    'End If
    End Sub
      

  2.   

    你这不是关闭了吗?CnNew.Close 建议用using(SqlConnection conn=new SqlConnection())
    //哈哈C#语法,不会VB,感觉应该也有相应的用法
      

  3.   

    我感觉也关了,可是就是没有办法写入数据库,Unload Me '关闭现有窗体 是不是程序退出?应该已经没有占用了吧?
      

  4.   

    不采用登录可以写入东西,不用这个vb登录界面直接登录就可以写入内容,用vb界面再登录就不能写入数据,是不是vb界面读取数据库以后没有完全释放,使数据库处于读状态没有办法写入啊?我的vb代码哪个地方没有关,请高手指点一下,谢谢