connectionstrings in website config files

2 posts, 0 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 30 Apr 2010 Link to this post

    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.
  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 05 May 2010 Link to this post

    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.
  3. DevCraft banner
Back to Top