Solved

Datasource Practices - ASP.NET connecstring

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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