关闭对象时不允许操作。 [英] Operation is not allowed when the object is closed.

查看:127
本文介绍了关闭对象时不允许操作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在globlemodel.vb声明的代码



globlemodel.vb



< pre lang =vb> 如果 conn.State = 1 然后 conn.Close()
conn.Open( 数据源= kamakhya-pc \sqlexpress;初始目录= dbEmployee;集成安全性= True; Provider = SQL Server的.NET Framework数据提供程序
' < span class =code-comment> conn.Open(Provider = SQL Server的.NET Framework数据提供程序;数据源= kamakhya-pc\sqlexpress;初始目录= dbEmployee;集成安全性= True)
MsgBox( 连接成功
返回 0
MsgBox( 连接成功
结束 功能







但是当我执行此操作时我得到一个错误



这是我在点击事件或登录按钮中的anoter代码



 私人  Sub  btnlogin_Click( ByVal  sender 作为系统。对象 ByVal  e 作为 System.EventArgs)句柄 btnlogin.Click 
如果 cmbutype。 Text = 员工 然后
sql = 从员工中选择*,其中empcode ='& txtuname.Text& 'and password ='& txtupass.Text& '
如果 rs.State = 0 然后 rs.Close()
rs.Open(sql,conn) )
如果 rs.EOF = False 那么
MDIMain.MasterToolStripMenuItem.Visible = False
MDIMain.EmployeeToolStripMenuItem.Visible = False
MDIMain.SearchToolStripMenuItem.Visible = False
MDIMain.LeaveToolStripMenuItem.Visible = False
MDIMain.EarnToolStripMenuItem.Visible = False
MDIMain.DeductionToolStripMenuItem.Visible = 错误
MDIMain.events.Visible = 错误
empid = txtuname.Text
MsgBox(登录成功)
MDIMain.Show()

< span class =code-keyword> Me 。隐藏()
结束 如果

否则
sql = select * from login其中Utypt ='& cmbutype.Text& 'and uname ='& txtuname.Text& '
如果 rs.State = 1 然后 rs.Close()
MsgBox( coonection close
rs.Open(sql,conn)
如果 rs.EOF = False 那么
sql = < span class =code-string> select * from login其中Utypt ='& cmbutype.Text& 'and uname ='& txtuname.Text& 'and upass ='& txtupass.Text& '
如果 rs.State = 1 然后 rs.Close()
rs.Open(sql,conn) )
如果 rs.EOF = False 那么
' MsgBox(登录成功)
MDIMain。 Show()
Me .Hide()
Else
MsgBox ( 密码不正确
结束 如果
其他
MsgBox( 登录失败

结束 如果
结束 如果

结束 Sub









所以任何一个人都可以帮我解决这个问题的原因当对象关闭时不允许操作。

解决方案

< blockquote>消息告诉你所有:你的代码尝试使用一个已关闭的对象!

我想你也被告知失败的地方。



因为事情还取决于仅在你的计算机上的部分(如文件),很难找到你的代码失败的原因。


我只能建议DIY解决方案:使用调试器并观察变量。

特别是,检查使代码失败的对象。



为您的错误消息关闭对象时不允许操作,只有几种可能性:

- 您错误地关闭了对象

- 一个打开的对象请求失败,你没有检查。

- 对象被误删除


this is the code which is declared at globlemodel.vb

globlemodel.vb

If conn.State = 1 Then conn.Close()
        conn.Open("Data Source=kamakhya-pc\sqlexpress;Initial Catalog=dbEmployee;Integrated Security=True;Provider=.NET Framework Data Provider for SQL Server")
        'conn.Open("Provider=.NET Framework Data Provider for SQL Server; Data Source=kamakhya-pc\sqlexpress;Initial Catalog=dbEmployee;Integrated Security=True")
        MsgBox("connection successfully")
        Return 0
        MsgBox("connection successfully")
    End Function




but when i execute this then i m getting an error

this is my anoter code in click event or login button

Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
        If cmbutype.Text = "Employee" Then
            sql = "select * from employee where empcode='" & txtuname.Text & "' and password='" & txtupass.Text & "'"
            If rs.State = 0 Then rs.Close()
            rs.Open(sql, conn)
            If rs.EOF = False Then
                MDIMain.MasterToolStripMenuItem.Visible = False
                MDIMain.EmployeeToolStripMenuItem.Visible = False
                MDIMain.SearchToolStripMenuItem.Visible = False
                MDIMain.LeaveToolStripMenuItem.Visible = False
                MDIMain.EarnToolStripMenuItem.Visible = False
                MDIMain.DeductionToolStripMenuItem.Visible = False
                MDIMain.events.Visible = False
                empid = txtuname.Text
                '   MsgBox("login sucess")
                MDIMain.Show()

                Me.Hide()
            End If

        Else
            sql = "select * from login where Utypt='" & cmbutype.Text & "' and uname='" & txtuname.Text & "'"
            If rs.State = 1 Then rs.Close()
            MsgBox("coonection close")
            rs.Open(sql, conn)
            If rs.EOF = False Then
                sql = "select * from login where Utypt='" & cmbutype.Text & "' and uname='" & txtuname.Text & "' and upass='" & txtupass.Text & "'"
            If rs.State = 1 Then rs.Close()
            rs.Open(sql, conn)
            If rs.EOF = False Then
                '  MsgBox("login sucess")
                MDIMain.Show()
                Me.Hide()
            Else
                MsgBox("Incorrect password ")
            End If
        Else
            MsgBox("login failed")

        End If
        End If

    End Sub





so any one help me what is the reason to geeting me Operation is not allowed when the object is closed.

解决方案

The message tells you all: your code try to use an object that is closed !
I guess that you are also told where is the fail.

As things also depends on parts that are only on your computer (like files), It will be very difficult to find why your code fails.

I can only suggest a DIY solution: Use the debugger and watch variables.
Particularly, check the object that make your code fail.

For your error message Operation is not allowed when the object is closed, there is only a few possibilities:
- you closed the object by mistake
- an open object request have failed, and you didn't check.
- the object is destroy by mistake


这篇关于关闭对象时不允许操作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆