If you are using a typed dataset (*.xsd) and you want to set it’s connection string, you can use the ObjectDataSource event OnObjectCreated.


protected void MyObjectDaDataSource_OnObjectCreated(object sender, ObjectDataSourceEventArgs e)
    if (e != null && e.ObjectInstance != null)
        SqlConnection connection = new SqlConnection("Data Source=SQLServerInstanceName1;
User ID=User1;Password=Password1;Initial Catalog=Database1;"); e.ObjectInstance.GetType().GetProperty("Connection",
BindingFlags.NonPublic | BindingFlags.Instance).SetValue(e.ObjectInstance, connection, null); } }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.