Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Appconfig
Message
From
11/05/2010 10:13:46
 
 
To
11/05/2010 08:48:07
Vishal Nyamagoudar
Swift Infocom India Pvt Ltd
India
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01464129
Message ID:
01464150
Views:
41
>Hello everyone
>PLs tel me how can i appconfig in my vb.net application for providing datasource path
>
>i want to design a form in which i wil input machine name like server\sqlexpress
>and database name when i click on save button i want save connection string in appconfigfile
>
>i m using vb.net and sqlexpress 2005
>
>how it can be done??

This (in C# but easy to convert) should write the connection string in the relevant section:
void WriteConnectionString(string name, string connectionstring)
        {
            System.Configuration.Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            cfg.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(name, connectionstring));
            cfg.ConnectionStrings.SectionInformation.ForceSave = true;
            cfg.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("connectionStrings");
        }
You can also use SQLDataSourceEnumerator to get a list of available SQL servers:
SqlDataSourceEnumerator sqlenum = SqlDataSourceEnumerator.Instance;
DataTable SQLList = sqlenum.GetDataSources();
Bear in mind that this doesn't write to the App.Config at runtime but to the [AppName].exe.Config file in the relevant bin folder.....
Previous
Reply
Map
View

Click here to load this message in the networking platform