Saving Connection Strings

I have a connection string as a varible "strConn". How would I save this to the config file so that my application would use the string to access the database using a button_click event to initialise it An example would be helpful.

 

Thanks

Spike




Answer this question

Saving Connection Strings

  • mandoman

    using 2005. However, I need the user to select the path. I have already done this and achieved "

    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + textBox2.Text

     

    which gives the elements for the string (povider etc) and attatches the path name of the database to the end (textbox2). The path for the textbox comes from a fileOpen dialog.

     ie. I get:

     

    Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\...\Database.mdb

    Also, because of the user needing to select the path, saving the path to the config file needs to be in the code, not just a setting.



  • Yosi Taguri

    Which Version of VS are you using If 2005, simply open the project properties, go to the settings tab, add a new setting (presumably with application scope) and set its type to "Connection String...".

    If you don't use integrated security to access your data source, beware that any stored usernames and passwords are in plain text, so potentially could result in security problems

  • Saving Connection Strings