I have found the second method unfortunately to be unstable. It seems that most of the time I cannot call the connectionstring when storing it in my app config when I try to preview the report in VS. I keep getting the error "Exception has been thrown by the target of an invocation. Object reference not set to an instance of an object.
" My app.config looks like this:
xml version="1.0" encoding="utf-8" ?>
add name="Adv" connectionString="Server=cmdivst004\Jason08;Integrated Security=true;Database=AdventureWorks" />
The call from the report code-behind looks like this:
SqlConnection conn = new SqlConnection();
string selectCommand = "SELECT * FROM Production.Product";
SqlDataAdapter adapter = new SqlDataAdapter(selectCommand, conn);
DataSet dataSet = new DataSet();
this.DataSource = dataSet;
this.DataMember = "Table";
This gives me the error.
However, when I call the db directly instead with the line below in the report codebehind, it works fine.
SqlConnection conn = new SqlConnection(@"Server=cmdivst004\Jason08;Integrated Security=true;Database=AdventureWorks");
Any ideas on how to fix this as i need to be able to store my connection info in one place if i create multiple reports.