Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Appconfig
Message
De
11/05/2010 10:13:46
 
 
À
11/05/2010 08:48:07
Vishal Nyamagoudar
Swift Infocom India Pvt Ltd
Inde
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01464129
Message ID:
01464150
Vues:
43
>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.....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform