none
ObjectDataSource bound to gridview using DataSet (.xsd) Would like to change connection string at runtime? RRS feed

  • Question

  • Hello,

    I am using an ObjectDataSource (for SQL Row_Number() paging).   The objectdatasource is referencing a dataset which calls stored procedures.  All is working great.
    I want to change connection strings between development and production environments at run time.  I have figured out how to change the dataset connection string using the below code:

    TesterStatusLists.TesterStatusListsTableAdapters.sp_GetTesterStatusTableAdapter obj = new TesterStatusLists.TesterStatusListsTableAdapters.sp_GetTesterStatusTableAdapter();
                obj.Connection.ConnectionString = strConnStr;

    I am having trouble finding out how to rebind the gridview datasource to the new tableadapter connection string at runtime.  Presently the connection string in the dataset is controlling which database I am connecting to

    Any assistance would be great.

    Thanks

    Joe

    Tuesday, May 26, 2009 6:23 PM

All replies

  • After doing a bit more pondering I figured out the solution.

    In the method referenced by the objectDataSource TypeName parameter I placed the following code,  which changed the connection string at run time:

    TesterStatusLists.TesterStatusListsTableAdapters.sp_GetTesterStatusTableAdapter adapter = new TesterStatusLists.TesterStatusListsTableAdapters.sp_GetTesterStatusTableAdapter();
            adapter.Connection.ConnectionString = strConnStr;

    Joe
    Tuesday, May 26, 2009 6:55 PM