On the Main-Form of a Project we have an Dataset and various DataTable-Objects.
We have generated the Dataset and the DataTable-Objects interactive.
We need the objects on the Form to make changes interactive and to link and design the various Datagrids on the Form.
At Design-Time we have placed the Connection-String in the Settings (including username and password) an then manually set the Connection-Property of the TableAdapter-Objects to the Connection-String in the Settings.
Everything works fine...
Now, we want to exclude the Password from Settings for Security (generate the password in Code) and we want to change the Database dynamically.
Now we generate dynamically a Connection-string in the Code with the generated password.
We change then the Connection-Propertys of the TableAdapter in the .New-Event of the Main-Form (this works).
Obviously the (interactive placed) Objects on the Form automatic wants to make Connections to the Database when the Main-Form loads.
At this time, the new (generated) Connection-String with the Password is not in Place -> an Error occurs.
If we change the ConnectionModifyer-Property of the TableAdapters from "Friend" to "Public" and modify the InitializeComponent-Event as follow:
- Me.XXTableAdapter.Connection = conn_string1
- Me.YYTableAdapter.Connection = conn_string1
it works (for one Time:-) without error.
The Problem is, that the Code in the InitializeComponent-Event is overwritten, everytime a new Version of the .exe is generated:-(.
Where do we have to place the Code (Me.XXTableAdapter.Connection = conn_string1)
for solve the Problem?
Thank you for a Solution:-)