Connection string

  • Thread starter Thread starter Ben Peeters
  • Start date Start date
B

Ben Peeters

Hi,

I 'm developing a multi-form windows application. I have to interact with a
database at different places. What is the best place to keep a connection
string to the database so that I can just access it right there?


Ben
 
Ben,
There are many different ways you can go about doing
this. I guess it depends on your authentication type to
the sql server. Is it a trusted Windows authentication,
or do you pass a sql server username/password?

If it is a trusted windows authentication you can just
store the connection string in the application config
file, read it when the app loads and store it in a
variable/object that is accessible whenever you need it.

If not, I would still suggest storing the server name,
and initial catalog in the config file, retreiving that
data when the app loads, create a connection string with
the username and password that the user entered. I would
also store this in some sort of a variable/object so you
can access it whenever you want because you don't want to
go through the hastle of creating the connection string
whenever you need it.

HTH
 
Back
Top