An object-oriented programming language developed by Microsoft that can be used in .NET.
AppDomain.CurrentDomain.SetData("DataDirectory", ...) only affects how connection strings that use |DataDirectory| are built when the connection is first created. Once the TableAdapter’s underlying SqlConnection has been created and opened, changing DataDirectory does not change the connection’s ConnectionString, nor does it force the adapter to rebuild or reopen it.
Result: after the first Fill, the TableAdapter keeps using the original connection (pointing to the first MyData.mdf), so subsequent Fill calls still read from the first database even though DataDirectory has been changed.
To load data from a different folder without restarting the app, the connection must be recreated (or its connection string updated) after changing DataDirectory. Typical patterns:
- Ensure the connection string in the
TableAdapteruses|DataDirectory|. - After calling
SetData("DataDirectory", ...), force theTableAdapterto use a newSqlConnectionbuilt from that connection string, or dispose and recreate theDataSet/TableAdapterinstance so that a new connection is created using the updatedDataDirectory. - Then call
OrganizationTableAdapter.Fill(MyDataSet.Organization).
ClearBeforeFill = True only clears the target DataTable before filling; it does not affect which database the adapter connects to.
References: