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

connectionstrings in website config files

1 Answer 175 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kellyroberts
Top achievements
Rank 1
kellyroberts asked on 30 Apr 2010, 07:12 PM
Hi all -

I have an asp.net website project (not web application) in vb ... call it web1... and a class library project also in vb ... call it web1report.  The reports are in the class library as recommended.  the report project is referenced in the website project.  I have a page in the website w/ a reportviewer pointing to a particular report.  The website has a web.config and defined in there is the same connectionstring 'strconn1'.  this connectionstring is used by several other pages in the web.  it is specifically defined as ...

<

 

connectionStrings>    

 

 

    <

 

add name="strconn1" connectionString="Data Source=server123\INS01,4101;Initial Catalog=ABC;Trusted_Connection=Yes" providerName="System.Data.SqlClient" />    

 

 

</

 

connectionStrings>

 

 

 

 

 

 

 

 

The report uses a sqldatasource and points to a connection string named 'strconn1'  ... same as website ... I told the report wiz to save the connection string.  I checked 'settings' for class library by r-clicking the project -> properties -> then the settings tab and I can see the connectionstring 'strconn1' listed there.

I can preview the report in VS2008 IDE just fine.  but when I try to browse the page w/ the report viewer I get

"Unable to connect to database. Please verify that your connection string is valid; in case you use a connection string from the application configuration file, make sure the name is correct and the connection string settings are present in the configuration file of your application."

now heres the weird part.  If I add another connectionstring in the web.config called web1report.My.MySettings.strconn1 ... like ...

 

<

 

 

 

add name="web1reports.My.MySettings.strconn1" connectionString="Data Source=server123\INS03,4103;Initial Catalog=ABC;Trusted_Connection=Yes" providerName="System.Data.SqlClient" />

 

 

 


then I can view the report

the problem is now i have 2 separate connection strings in my project ... and I dont really like that ...

can someone exlpain why its a problem in the first place, and how i can avoid using 2 separate connectionstrings ?

I also read this forum post and it helps but I thought that as long as I have the same connectionstring name in both projects it should be ok. 

is it somehow related to application.settings?  im not sure the website has 'settings' only web.config

Any help is appreciated.

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 05 May 2010, 01:40 PM
Hello kellyroberts,

The connection string name is serialized in this fashion: (web1reports.My.MySettings.strconn1) because of the project's application settings. You can still add the short name to the app.config and use it for the datasource components but then the designer preview will not work. The easiest way to get the report working in your app is to copy the exact connectiongString from the app.config of the report library.

Sincerely yours,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
kellyroberts
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or