Solved

Datasource Practices - ASP.NET connecstring

Posted on 2004-10-04
1
511 Views
Last Modified: 2008-03-04
Hi,

i have a db connection like this

dbpath="d:\database\data\CRM.mdb"
username="admin"
password="password"

then connecstring of

            Me.pvtConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" _
                      & "User ID=" & Me.username& ";" _
                      & "Data Source=" & Me.dbpath& ";" _
                      & "Jet OLEDB:Database Password=" & Me.password& ";"

Before, when i run asp (developed using dreamweaver), i could just change the dbpath to sumthing else.
Now, i have converted it to VB.net asp project.
now i cant change the DBpath anymore, i have to recompile and deploy it back to the server.

How do you guys do it?
best practices?

0
Comment
Question by:Jerry_Pang
1 Comment
 
LVL 3

Accepted Solution

by:
skpatra earned 250 total points
ID: 12215782
You have configuration files in .net applications. Config files provide coniguration information at runtime and the great thing about the config files is that you can change the configuration information without recompiling the program. So here are the steps:

1. In your VB.Net application, open the web.config file. If you are not using VS.Net, then just add a file called web.config under the root directory of your website.  It should lok something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
   .
   .
   .
  </system.web>
</configuration>

2. Now, add your DBPath as a configurable parameter under a tag called appSettings.

<configuration>
  <system.web>
   .
   .
   .
  </system.web>
  <appSettings>
    <add key="DBPath" value="d:\database\data\CRM.mdb" />
  </appSettings>
</configuration>

3. In your code you can read this value as
    dbpath = System.Configuration.ConfigurationSettings.AppSettings.Item("DBPath")

Now, you can change the value of DBPath in the web.config file without recompiling the application. Refer to the following url for a detailed demo of the configuration files.

http://samples.gotdotnet.com/quickstart/aspplus/doc/configretrieve.aspx

Hope this helps...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now