Backgroundworker和OleDbConnection [英] Backgroundworker and OleDbConnection

查看:71
本文介绍了Backgroundworker和OleDbConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB.Net的新手。我有一个背景工作程序例程,它与UI共享OleDBConnection。请注意,当backgroundworker使用OleDBConnection时,UI例程不会使用它。奇怪的是,当我在设计环境(visual basic express 2010)中运行程序时,它运行正常。但是当我在其他计算机上运行可执行文件时,它会在OleDb.OleDbDataReader行停止。我在整个程序中使用了connection.open和.close语句 - 它再次在设计环境中工作。有没有人见过这个?我需要做什么?

I am new to VB.Net. I have a backgroundworker routine that shares OleDBConnection with UI. Note when backgroundworker uses OleDBConnection, it''s not used by UI routines. The strange thing is when I run the program in design environment (visual basic express 2010), it works fine. But when I run the executable in other computers, it stops at OleDb.OleDbDataReader line. I use connection.open and .close statement throughout the program - again it works in the design environment. Has anyone seen this? What do I need to do?

推荐答案

不要通过代码共享单个连接对象。



在需要时创建一个新对象,使用它,在完成查询后进行处理。在整个代码中共享单个连接对象没有任何好处。
Don''t "share" a single connection object through out your code.

Create a new object when you need it, use it, dispose it when you done with the query. There is no advantage to "sharing" a single connection object throughout your code.


这篇关于Backgroundworker和OleDbConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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