创建表单对象时出现未指定的错误.... [英] Unspecified Error on create of a form object....

查看:110
本文介绍了创建表单对象时出现未指定的错误....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我为Restaurant开发了一个软件,所以我需要同时运行多个表单实例(Billing表单)。



我为数据库连接和操作(插入,更新和删除Rocords)创建了类Data_Con,它有一个构造函数参数,它接受数据库路径。这个类在每个表单中用作全局变量,并在表单构造函数中初始化该对象...

它可以很好地创建10或12个表单创建实例,但之后它给出了一个错误(错误)显示在消息框中)未指定的错误。发生错误后,每次打开任何表单时都会显示,主要是在表单代码无效的错误之后(如它没有从数据库中获取数据)..



我的表单构造函数代码是: -



Hi,
I developed a software for Restaurant, so I need to run multiple instance of a form(Billing form) concurrently.

I created a Class "Data_Con" for Database connection and manipulation (Insert, Update and Delete Rocords),Its has a constructor parameter which take the database path. This class used in every forms as a global variables,and initialize that object in form constructor...
Its going fine upto 10 or 12 Instance of form creation, but after that its given an error(error showing in message Box) Unspecified Error.After that error was occurred, It's show on every time when any form is opening, mainly after the error that forms codes are not working(like its not getting data from database)..

My form constructor code is :-

public NewBill(string para,Form1 mainFrm)
        {
            InitializeComponent();
            MF = new MiscFunction();
            DC = new Data_Con(Application.StartupPath);
            menu = new Data_Con(Application.StartupPath);
            Auth = new Data_Con(Application.StartupPath);
            menuRate = new Data_Con(Application.StartupPath);
            itemEntry = new Data_Con(Application.StartupPath);
            NTW = new NumToWord();
            ParaValue = para;
            mdiFrm = mainFrm;
        }



代码是Data_Con的构造函数:


Code is Constructor of "Data_Con" :

public Data_Con(string path)
        {
            try
            {
                conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + path + "\\MrityunData.accdb;Jet OLEDB:Database Password=power;");
                conn.Open();
                adpt = new OleDbDataAdapter("select * from Bill_details", conn);
                dataSet = new DataSet();
                cmd = new OleDbCommand();
            }
            catch(Exception e) {
                MessageBox.Show(e.Message);
            }
        }





这里你可以看到我创建了Data_Con的多个对象类,每次对象初始化时显示错误(5次)。



如何解决该错误?



感谢先进...



问候

Jayanta ..



Here You can see I created multiple object of "Data_Con" Class,the error show on every Object Initialization(5 times).

How to solve that error??

thanks in advanced...

Regards
Jayanta..

推荐答案

我是否正确您正在创建一个新的SqlConnection对象并为每个Data_Con类实例打开它?如果是这样,那么你可能犯了一个大错误。如果不确切知道你的系统是如何设置的,你很可能会耗尽并发连接(例如,Win7下的某些版本的Sql Express只允许20个,但是你的系统可能会有所不同)



如果您这样做,请尝试打开连接,使用它们并再次关闭它们 - 无论如何,它通常被认为是更好的做法。
Am I right that you are creating a new SqlConnection object and opening it for each Data_Con class instance? If so, then you are probably making a big mistake. Without knowing exactly how your system is set up, you may well be running out of concurrent connections (some versions of Sql Express under Win7 only allow 20 for example, but it may be different in your system)

If you are doing this, try opening the connections, using them, and closing them again - it's generally considered better practice anyway.


这篇关于创建表单对象时出现未指定的错误....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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