How to write a config file to connect database ?

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'"
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top