none
need an example to establish a connection to sqlserver using singleton pattern RRS feed

  • Question

  • Hi All,

       I am new to designs and patterns. I want to know how to establish a DB connection  using singleton pattern. Please guide me on this.

    Tuesday, August 13, 2019 3:13 PM

Answers

  • Hi Sai,

    Thank you for posting here.

    According to your description, you want to have an example to connect sqlserver by using singleton pattern.

    I find the following link may be helpful for you.

    https://gist.github.com/IsTheJack/5bfc3679bd0962b1bb9c

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 2:48 AM
    Moderator

All replies

  • Hello,

    Out of curiosity, why use a singleton for your connection? It's much easier no matter how many time a connection is needed to write a connection in a "using" statement which means each time the connection is closed and disposed while with a singleton class you need to check for the various states of a connection e.g. Broken, Closed, Open. 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, August 13, 2019 3:37 PM
    Moderator
  • Hello, 

    >Please guide me on this.

    Easy.

    1. Read about Singleton Pattern

    2. Write code which implement Singleton Pattern

    3. Ensure that implementation contain a Singleton Pattern

    4. Convert code you create to represent "DB connection".

    On each stage - report progress and misunderstanding of content.


    Sincerely, Highly skilled coding monkey.

    Tuesday, August 13, 2019 4:17 PM
  • Hi Sai,

    Thank you for posting here.

    According to your description, you want to have an example to connect sqlserver by using singleton pattern.

    I find the following link may be helpful for you.

    https://gist.github.com/IsTheJack/5bfc3679bd0962b1bb9c

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 2:48 AM
    Moderator