Database connection in c#
-
I was wondering what is the best way to deal with database connections in c# windows application. Is it good practice or not to pass a connection string through the application and open a connection object when you need to query the database or is it better to keep a database connection open throughout the application. It is my understanding that it is better to open a connection when you need it. Is there any security risks in accessing a connection string through a static property in my application or is there a better way of accessing the connection string throughout the application? I would be interested to hear any-bodies suggestions. Thanks
-
I was wondering what is the best way to deal with database connections in c# windows application. Is it good practice or not to pass a connection string through the application and open a connection object when you need to query the database or is it better to keep a database connection open throughout the application. It is my understanding that it is better to open a connection when you need it. Is there any security risks in accessing a connection string through a static property in my application or is there a better way of accessing the connection string throughout the application? I would be interested to hear any-bodies suggestions. Thanks
-
We use a configuration file for the connection information. The strings are encrypted for security. if there is a change, we can adjust the connection strings without compiling and deploying. ed Regulation is the substitution of error for chance.
The application uses the username and password that the user provides, not a default system account. Therefore it picks up the database security/permissions to tables/views etc. Any thoughts about securing the connection string in this sort system. Thanks
-
The application uses the username and password that the user provides, not a default system account. Therefore it picks up the database security/permissions to tables/views etc. Any thoughts about securing the connection string in this sort system. Thanks
Build your connection string externally and use tokens for the username and password that can be replaced through code before they are used. I like to use [%USERNAME%] and [%PASSWORD%] as my tokens.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.
-
Build your connection string externally and use tokens for the username and password that can be replaced through code before they are used. I like to use [%USERNAME%] and [%PASSWORD%] as my tokens.
Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.
At the moment I have a private member variable with I store the connection string in. I make this variable accessible through a public static property. What are the benefits of using the token methods? Is the static property a good or bad way to store the connection string. Getting back to the orignal post what do people think good practice is for handling database connections?