An object-oriented programming language developed by Microsoft that can be used in .NET.
Hello @James Buss ,
Thanks for your question.
I recommend investigating the connection string resolution and connection pooling behavior. The DataDirectory token in the connection string appears to be resolved during the initial connection establishment. ADO.NET's connection pooling likely caches this connection with the originally resolved path. When you update the DataDirectory value, I suspect the pooled connection continues referencing the initial database file instead of re-evaluating the token with the new path.
You can refer to my following example code:
Imports System.Data.SqlClient
Private Sub LoadDatabaseFromFolder()
If FolderBrowserDialog1.ShowDialog() <> DialogResult.OK Then Return
If OrganizationTableAdapter.Connection IsNot Nothing Then
OrganizationTableAdapter.Connection.Close()
End If
OrganizationTableAdapter.Dispose()
SqlConnection.ClearAllPools()
AppDomain.CurrentDomain.SetData("DataDirectory", FolderBrowserDialog1.SelectedPath)
OrganizationTableAdapter = New OrganizationTableAdapter()
MyDataSet.Organization.Clear()
OrganizationTableAdapter.Fill(MyDataSet.Organization)
End Sub
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.