How can I write my SQL Connection for my application?

Hi

I have been developing one database application in VC++ .NET with SQL Server 2000. The Software have more child forms for the related databases and its record navigation functions. Now I want to make SQL Connection as global for all the child forms to avoid connection while loading the child form. Because its taking more time. Please give your sample code and suggestion. Where I can get sample code

Thanks
Joseph TA
Email: joseta@vsnl.com
Tel: 0024398356388/00243817300066
Kinshasa,DR Congo


Answer this question

How can I write my SQL Connection for my application?

  • Kojacked

    You can use SingleTon Connection..
    its mean you have just one Connection instance.

    http://dofactory.com/Patterns/PatternSingleton.aspx  -> you can look at here for singleton design pattern.

    if you want to create your own Connection class..
    You can use System.Data.Common.DbConnection

    it is an abstract class... so you can override its methods ;)


  • The Markus

    Are you calling Connection.Dispose after use

    This should return the connection to the pool and not really release it from memory. The next connection that is created with the same connection string should return a previously created connection. If you fail to call dispose, the connection is not released until garbage collection occurs which causes a new connection to actually be created the next time new connection is called instead of getting it from the pool.

    In any method that requires a connection, I almost always create a new connection and dispose the connection before I leave the method and I have seen no slow down.

    Read up on connection pooling and confirm you are adhering to usage guidelines.

  • Sudha

    Hi,


    You could try creating a class with a static variable connection object...


    ref class Globals {
    public:
       static SqlConnection^ conn = gcnew SqlConnection(<connstr>);
    };

    In that way you could use it across the namespace...





    cheers,


    Paul June A. Domag

  • How can I write my SQL Connection for my application?