How to write a config file to connect database ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

In my application, there is an hard code string ,to connect the database.
Can I use config file instead of it ?? Please Help & Thx.
Public Shared CONNECTION_STR_ACCOUNT As String = "workstation
id=AGNES;packet size=4096;user id=sa;data source='hlssql';persist security
info=True;initial
catalog=dts_account;password='sys+em'"
 
Hi,

There are so many ways to store the Connection String like (i) Hard-Coding
in application [the way you have used], (ii) Storing in Registry OR (iii) In
Application's Configuration File. The last option i think is the best.
You can do this by editing config file as: ->

<configuration>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Connection string values -->
<add key="Provider" value="MSDAORA" />
<add key="DataSource" value="DBTest" />
....Add Keys For Any Further Details...
</appSettings>
</configuration>
Now you can call thse setting easily from your application.

Mayur S. Wakade (Tendulkar)
Electrical Engineer
Pune, India
 
Back
Top