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" ?>
<
configuration>
<
configSections>
</
configSections>
<
connectionStrings>
<
add name="Adv" connectionString="Server=cmdivst004\Jason08;Integrated Security=true;Database=AdventureWorks" />
</
connectionStrings>
</
configuration>
The call from the report code-behind looks like this:
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["Adv"].ConnectionString;
string selectCommand = "SELECT * FROM Production.Product";
SqlDataAdapter adapter = new SqlDataAdapter(selectCommand, conn);
DataSet dataSet = new DataSet();
adapter.Fill(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.
Jason