Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I have an application with SQL EXPRESS database.
I have created a form to connect to SQL SERVER with four textboxes.
textbox1 = server
textbox2 = database name
textbox3 = user
textbox4 = pass
I want when I fill the textboxes with data to change the data in connectionstring in app config file

can anyone give examples for this

Thanks in advance

VB

Posted

Use [ApplicationNameSpace.Properties.Settings.Default.ConnectionStringName] to access your Connection string in the app.config file.

But am worried, because it seems that there is no way you can access the value property in order to change it, instead you can only read the value.

Why don't you instead save your connectionString to the registry? There you can edit/read it any time you want
 
Share this answer
 
Comments
jomachi 7-Apr-13 4:08am    
Can you give me an example for registry
C#
using Microsoft.Win32;

//Writing to the registry

string ConnectionStringValues = TextBoxServer; + TextBoxUID;...; 

 RegistryKey regkey = Registry.CurrentUser.CreateSubKey(@"Software\YourSoftwareName\RegistryKey");
regkey.SetValue("ConnectionStringName", "ConnectionStringValues");

//Reading from the registry (Getting your connectionString)
RegistryKey regkey = Registry.CurrentUser.CreateSubKey(@"Software\YourSoftwareName\RegistryKey");
regkey.GetValue("ConnectionStringName").ToString();


/*
Don't forget to create the registry key first in the registry
Open Run -> Type in the command regedit,
Expand HKEY_CURRENT_USER,
Locate and RightClick on Software folder,

New -> Key (Name it ConnectionStringName or any other name you prefer),
Right Click on the folder you created and choose: New ->String Value
You can leave the value field blank or initialize it with your current connection string

Also remember to include these registries when building your installer

Regards
*/
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900