Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok, my first C# WinForm ..

 

I have a menu: File --> connect to Database

 

So we want to connect to a database in one place, once in the beginning of the app ..Users enter the database name, userid and password...

 

So, how should I do this? Write a "connection" class and pass the parameters to the class? Do the connection in the code behind of the form when the user clicks "connect" button??

 

what is the best way of doing this?

Posted (edited)

I usually keep one internal sealed class that encapsulates all of the objects and code that the application needs to interact with the data source....I would suggest having a class similar to this in which you store the connection string you build from the user's input in a private static field. Then have a public static 'GetConnection()' method that returns a connection when needed. There are obviously many other things to consider in regards to security, exception handling/recovery, etc...but that is the basic gist of one way to handle data connections.

 

Ok, my first C# WinForm ..

 

I have a menu: File --> connect to Database

 

So we want to connect to a database in one place, once in the beginning of the app ..Users enter the database name, userid and password...

 

So, how should I do this? Write a "connection" class and pass the parameters to the class? Do the connection in the code behind of the form when the user clicks "connect" button??

 

what is the best way of doing this?

Edited by RobEmDee

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...