none
Store and Retrieve ConnectionString from Properties.Settings file in run time using C#... RRS feed

  • Question

  • Hallo once again!

     

    I developed an application that connects to a database using a connection string. In design time I store it to the application configuration file and all my components retrieve this from there using the following snippet:

     

    Code Snippet

     

    String ConnectionString = Properties.Settings.MyStoredConnectionString

     

     

    The problem starts when i tried to change the stored value of MyStoredConnectionString to a new ConnectionString in runtime using the next code:

     

    Code Snippet

     

    // This code doesn't work

    Properties.Settings.MyStoredConnectionString = ConnectionString;

     

     

    Error occures saying "Properties.Settings.MyStoredConnectionString is read - only and cannot be assigned". Is there a way to save my new connection string back to application configuration file in run time?

     

    Thanks in advance,

     

    Patonios

     

    P.S Please do not suggest me to create another Settings File and store my connectionstring there.

     

    Sunday, April 13, 2008 1:48 PM

All replies