TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abraham Olatubosun
NA
471
114.9k
How to Change web.config ConnectionString dynamically
Apr 4 2017 6:59 AM
Dear Code Master,
I hope this question meet in good health, i am writing an application, i have finished writing and every thing is working we upload it to cloud for the client from time to time their is the need to make some amendment that also had to affect the database.
When we re-upload we need to make changes to the connection string in web.config, we them impliment changing the web.config dynammically that ir from run time we put some text boxes and a submit button when the button is click by the client it should edit the web.config connectionstring section and update it with the new connection string.
we have tried the following:
// ===========================================
// The content of pathname is shown below
// string pathname = "~/web.config";
//============================================
System.Configuration.Configuration Config1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(pathname);
ConnectionStringsSection conSetting = (ConnectionStringsSection)Config1.GetSection(
"connectionString"
);
ConnectionStringSettings StringSettings =
new
ConnectionStringSettings(
"NIQSDB"
,
"Data Source="
+ ServerName +
";Database="
+ DBaseName +
";User ID="
+ UserID +
";Password="
+ PSSWD +
";"
);
conSetting.ConnectionStrings.Remove(StringSettings);
conSetting.ConnectionStrings.Add(StringSettings);
Config1.Save(ConfigurationSaveMode.Modified);
and i am getting the following error
Object reference not set to an instance of an object.
at
conSetting.ConnectionStrings.Remove(StringSettings);
please what am i doing wrongly.
thank you
Reply
Answers (
1
)
How to test dropdownlist is null or not
in which scenario people use factory design patter.