Change My.Settings ConnectionString in runtime?

Posted by Sultanen on Stack Overflow See other posts from Stack Overflow or by Sultanen
Published on 2012-09-08T19:37:25Z Indexed on 2012/09/08 21:38 UTC
Read the original article Hit count: 359

I have a ClickOnce deployment where i have a INI-settings file on the network file with "global" settings that is supposed to affect the program on all client computers. The problem i have is that i whant to have the Database connectionString stored in this INI file and have it read and stored in the My.Settings ConnectionString at program startup. How do i do this? The ConnectionString setting is Application scoped and therefore Read-Only, if i try to set it by My.Settings("ConnectionString") = "Source=server;Initial Catalog=database;Integrated Security=True" I get a runtime error:

An error occurred creating the form. See Exception.InnerException for details. The error is: The type initializer for 'DB_lib.DB_LINQ' threw an exception.

[EDIT] I got rid of the error by using the My.Settings("ConnectionString") = "Source=server;Initial Catalog=database;Integrated Security=True" in another place then the the eventtriggerd settingsLoaded method i created.. The problem is that even though the connectionstring semes to be the right, the program still connects to the "default" database that is typed in to the app.config file??

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about visual-studio