Solved

Datasource Practices - ASP.NET connecstring

Posted on 2004-10-04
1
513 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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