This is a migrated thread and some comments may be shown as answers.

No data in Design Preview

1 Answer 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jorge
Top achievements
Rank 1
Jorge asked on 23 Jul 2009, 01:01 PM
If the table adapter in dataset use connection string stored in Web.config, the report works OK when running the web page but show no data while previewing in Design mode.

I tried the solution proposed in forums but didn't work.
            ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["myConnectionString"]; 
            if ((connSettings != null) && (connSettings.ConnectionString != null)) 
            { 
                this.hospitalDataSetTableAdapter1.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; 
            } 
 

I debug Design Preview with a MessageBox like this...
            } 
            catch (System.Exception ex) 
            { 
                // An error has occurred while filling the data set. Please check the exception for more information. 
                MessageBox.Show(ex.Message); 
                System.Diagnostics.Debug.WriteLine(ex.Message); 
            } 

and I get "Object not set to an instance of an object"

What am I missing?
Thanks a lot!

1 Answer, 1 is accepted

Sort by
0
Jorge
Top achievements
Rank 1
answered on 23 Jul 2009, 01:13 PM
I traced the exception and It's generated inside InitConnection() in table adapter.
     private void InitConnection() { 
            this._connection = new global::System.Data.SqlClient.SqlConnection(); 
            this._connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; 
        } 

Somehow System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"] it's not initializing correctly.
Again: This only happens in Design Time.

More ideas?
Tags
General Discussions
Asked by
Jorge
Top achievements
Rank 1
Answers by
Jorge
Top achievements
Rank 1
Share this question
or