Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :-

C#
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;
        }

Code is Constructor of "Data_Con" :
C#
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);
            }
        }


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..
Posted
Updated 25-Aug-13 5:01am
v2
Comments
Valery Possoz 25-Aug-13 10:54am    
What is the code in the constructor of Data_Con?
JayantaChatterjee 25-Aug-13 11:02am    
Sir, I updated my Question. Please See....

1 solution

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.
 
Share this answer
 
Comments
JayantaChatterjee 25-Aug-13 11:57am    
Oooo.. I got the Mistakes...
Now I create and dispose the object after using,its working fine..
Thanks Sir, Thanks a Lottttttttttttttttt....
Thanks Sir... :-)
OriginalGriff 25-Aug-13 12:00pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900