Set DB Connection object global for all forms

Hello,

I'm making a winform application who work with Oracle. I need to be always connected to oracle, since the application start to the application stop.

The main form of this application is an MDI Form, on most of the other form are MDI Child.

I would like to create a  Database object connection only one time, then i will be able to use this object in all MDI child of the application. Is it possible 

Actualy, i make a DB Connection for all form loaded, like this :
 OracleConnection m_oConn = new OracleConnection(connectionstring);

Is it possible to share a DB object between form   in this case how can i make 

Thank For All.








Answer this question

Set DB Connection object global for all forms

  • DPP

    public class OracleDB
    {
         public static OracleConnection Connection;
    }


    public class MyClass
    {
        public MyClass(string connectionstring)
        {
         OracleDB.Connection = new OracleConnection(connectionstring);
         }
         public void DoSomthing()
         {
               cmd.Connection = OracleDB.Connection;
          }
     
    }

  • Kev-ster

    It's work very good !

    Great Thank

  • Set DB Connection object global for all forms