how to change connection string dynamically in object datasource in asp.net ?
views:
868answers:
2
+4
A:
protected void ObjectDataSource1_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
{
if (e.ObjectInstance != null)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = MyConnectionManager.ConnectionString;
e.ObjectInstance.GetType().GetProperty("Connection").SetValue(e.ObjectInstance, conn, null);
}
}
I hope it helps.
Braveyard
2008-12-13 04:40:23
A:
I didn't get the above to work but this did:
if (e.ObjectInstance != null)
{
((ReportPrototype.ReleasedRatingsDataTableAdapters.RatingsViewTableAdapter)e.ObjectInstance).Connection.ConnectionString = ConfigurationManager.ConnectionStrings["RADSDataConnectionString"].ConnectionString;
}
ObjectInstance is the table adapter which in my case was the type bound to the ObjectDataSource.