To change an object data source connection string dynamically at runtime, try this:
We'll use "ods" as the object name for this example.
Protected Sub ods_ObjectCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceEventArgs) Handles ods.ObjectCreated If e.ObjectInstance IsNot Nothing Then Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection conn.ConnectionString = ConfigurationManager.ConnectionStrings("newconnstring").ConnectionString e.ObjectInstance.GetType.GetProperty("Connection").SetValue(e.ObjectInstance, conn, Nothing) End If End Sub
You must also set the "ConnectionModifier" of the table adapter for the object to Public.
In this example, the new connection string is stored in web.config, as "newconnstring".