Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bernie 11 posts 25 karma points
    Jan 29, 2011 @ 23:40
    Bernie
    0

    Using Web.Config for connection strings?

    [Plz forgive me if this is not in the proper place, however, I couldn't find a better developer catagory...]

    I'm attemtping to create a user control with a SQLDataSource.  When configuring the datasource I select the drop down on the "Choose Your Data Connection" dialog box and I can see my connection string which I've placed in the web config.  After completing a few more steps of the configuration I can test the query and it returns data just fine.  If I run the user control inside Umbraco I get the "Cannot load user control..." error.

    If I use the exact same string data wired up directly in the SqlDataSource markup (just copying and pasting from the web.config), it works fine.  Why doen't it work with Umbraco?

     

     

     

    So... This works:

    <

     

     

    asp:SqlDataSource ID="SqlDataSource1" runat="server"

     

     

    ConnectionString="Data Source=localhost;Initial Catalog=stti-umbraco-local;UId=stti-umbraco;Pwd=stti-umbraco;Pooling=false"

     

     

    ProviderName="System.Data.SqlClient"

     

     

    SelectCommand="SELECT * FROM [STTIVoteSurveyDetails]"></asp:SqlDataSource

    >

     

     

    This fails only when run inside Umbraco despite the string being in the web.config and VisualStudio testing it just fine:

     

     

    <

     

     

    asp:SqlDataSource ID="SqlDataSource1" runat="server"

     

     

    ConnectionString="<%$ ConnectionStrings:dbConn-sttiUmbraco %>"

     

     

    SelectCommand="SELECT * FROM [STTIVoteSurveyDetails]"></asp:SqlDataSource

    >

     

    Thanks,

    Bernie

  • Harald Ulriksen 207 posts 249 karma points
    Jan 30, 2011 @ 00:39
    Harald Ulriksen
    0

    Hi Bernie,

    are you trying to run the user control in the umbraco back-end (/umbraco/umbraco.aspx) or on a front-end page? 

    Can you include more of your error message? A stack trace will help a lot.

    /Harald 

  • Bernie 11 posts 25 karma points
    Jan 30, 2011 @ 07:08
    Bernie
    0

    No, I've just added the user control to a template using a macro and then generated a content page from the template. 

    Error:

    Error creating control (/usercontrols/website/Survey/ShowSurveyQuestions.ascx).
    Maybe file doesn't exists or the usercontrol has a cache directive, which is not allowed! See the tracestack for more information!

    All I have to do to get this to work is to take the connection string out of the web config and paste it in place of the <%$  ConnectionStrings:dbConn-sttiUmbraco %> , but, I can see that the connection string is correct and test it using Visual Studio in the same user control. 

    I'm showing my inexperience here, but, how to I get the stack trace?

  • Harald Ulriksen 207 posts 249 karma points
    Jan 30, 2011 @ 11:15
    Harald Ulriksen
    0

    Ok, to get the stack trace you can add

    ?umbdebugshowtrace=true

    to the querystring. Look for the red parts.

    Also, are you sure you have a server side form tag in the template?

    <form runat="server" name="someformname">

     

  • Bernie 11 posts 25 karma points
    Jan 31, 2011 @ 00:15
    Bernie
    0

    Thanks for the feedback.  I had the page working as described with the static conn string.  Trying to provide more information I went back into the page and added a sqlDS, following the exact same steps I had before and using a connection string from the web.config .  Now, it works.  I have no idea why.  The only thing I can think of is that I had restarted my workstation inbetween the error and it now working.

    Why it is working now, and didn't before, is a complete mystery since I'm 100% positive I followed the same steps.

    So, thank you but it appears to be working just fine now.  The trace route info will be helpful too!

Please Sign in or register to post replies

Write your reply to:

Draft