We help IT Professionals succeed at work.

ASP.net best way for user to change location of Access database

Murray Brown
Murray Brown asked
on
Medium Priority
181 Views
Last Modified: 2012-05-12
Hi

I have an ASP.net site that sits on an IIS Server accessing an Access database somewhere else on the network. This database is periodically moved to a different location and I want to know the best way for a USER to change the location so that all my VB.net code automatically picks up this location. On a LAN what is the best way to do this? I see the Access Data Source control. Is this an option? If I put it in the web config area then this has to be changed in code.
Comment
Watch Question

Vikram Singh SainiWeb Developer
CERTIFIED EXPERT

Commented:
The best place for changing common configurations of website is Web.config.

You would need to change connection string in web.config so that all changes would be visible for whole website.
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Hi

Thanks. Is it possible to programatically change the web.config connection  info?
Web Developer
CERTIFIED EXPERT
Commented:
Yes!

You can use System.Web.Configuration namespace.

protected void SaveSettings()
    {
        Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");

        ConnectionStringsSection settings = (ConnectionStringsSection)webConfig.GetSection("connectionStrings");

        settings.ConnectionStrings["conString"].ConnectionString = "Value";
        webConfig.Save(ConfigurationSaveMode.Modified);
    }

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
thanks very much

Explore More ContentExplore courses, solutions, and other research materials related to this topic.