1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / database connection

database connection

17 posts, 1 answered
  1. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    20 Mar 2012
    Link to this post
    Hello,
    I have made a module (with Radrotator) that get a picturs (from a SQLEXPRESS database) and display it,that work greate,so now i would like to integrate it (like a widget) to used it in my sitesinity 5 project but i get an error about the string connection,where do I défine it ? 
    The error is , and how can i resolve this problem ?

    The connection name 'CantonConnectionString' was not found in the applications configuration or the connection string is empty.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: The connection name 'CantonConnectionString' was not found in the applications configuration or the connection string is empty.

    Source Error: 

    The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

    1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

      <%@ Page Language="C#" Debug="true" %>

    or:

    2) Add the following section to the configuration file of your application:

    <configuration>
       <system.web>
           <compilation debug="true"/>
       </system.web>
    </configuration>

    Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

    Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

    Thanks  
  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    20 Mar 2012
    Link to this post
    Hey Med,

    SQL Connections are stored in the DataConfig.config file. You can find it by going from the root folder of your project to App_Data/Sitefinity/Configuration.

    When you open the file, you'll find the default connection string for the Sitefinity database already there.

    Jochem.
  3. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    20 Mar 2012
    Link to this post
    Thank you for the reply,
    I attached the database when I created the project, and I added the connection string ("CantonConnectionString") in the file dataconfig.config but i get this error :

    Server Error in '/CantonComm' Application.

    The connection name 'CantonConnectionString' was not found in the applications configuration or the connection string is empty.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: The connection name 'CantonConnectionString' was not found in the applications configuration or the connection string is empty.

    Source Error: 

    Line 45: 
    Line 46:         <br />
    Line 47:         <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    Line 48:             ConnectionString="<%$ ConnectionStrings:CantonConnectionString %>" 
    Line 49:             SelectCommand="SELECT [Id] FROM [ArtisteImageBlog]">

    Source File: c:\Program Files\Telerik\Sitefinity 5.0\Projects\CantonComm\App_Data\Sitefinity\WebsiteTemplates\Theme01\WidgetTemplates\widget\Default.ascx    Line: 47 
     

    Thank you again 
  4. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    20 Mar 2012
    Link to this post
    Hey Med,

    Euhm if I'm not mistaking the <%$ is the culprit, I think it should be <%= instead so you'll get 

    ConnectionString="<%= ConnectionStrings:CantonConnectionString %>"

    I could be wrong but $ can't be used on the server side I believe..

    Jochem.
  5. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    20 Mar 2012
    Link to this post

  6. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    20 Mar 2012
    Link to this post
    Hey Med,

    Your post doesn't show up here but I received it in the email. The problem with the code is your trying to paste .aspx code into an .ascx. (an .aspx is a full page, a .ascx is just a snippet you 'paste into' a full page. So all the doctype/html/form/body etc needs to be removed)

    Best way to fix it is to go into VisualStudio and under project select Add new Item. From the new window select "Web user control". This will create an .ascx file with some code behind, and you end up with this:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="SitefinityWebApp.WebUserControl1" %>

    Underneath paste the following (from your snippet):
    <div>
     <telerik:RadRotator ID="RadRotator1" runat="server" DataSourceID="SqlDataSource1" AppendDataBoundItems="True">
        <ItemTemplate>
            <asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Id", "Handler.ashx?Id={0}") %>'/>
        </ItemTemplate>
     </telerik:RadRotator>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%= ConnectionStrings:CantonConnectionString %>"
        SelectCommand="SELECT [Id] FROM [ArtisteImageBlog]">
     </asp:SqlDataSource>
    </div>

    And then register the file in the Sitefinity toolbox.
  7. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    21 Mar 2012
    Link to this post
    hi Jochem and thanks a lot for your help,
    Now I dont have any error but the RadRotator does not display the images,I dont know why ! I just fellow the same steps . I attach the pictures that show that .
    Thankx again 
  8. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    21 Mar 2012
    Link to this post
    Dear Med
    I would use Fiddler2.com to see what is happening.What is tried to be loeaded and what's the error.
    Markus
  9. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    21 Mar 2012
    Link to this post
    Hey Med,

    With each step where getting closer no?

    Since you're using Chrome as a browser you can right click one of the 'broken image' icons and click 'inspect element'. This will show you the rendered source of the html and might give a clue as to why the images aren't showing. (see screenshot 1) 

    Next to that you can click the 'resource tab' and reload the page. If you scroll up/down you'll see all individual files being loaded (or not). The ones Chrome couldn't load will show up in red and have a status of 404. (see screenshot 2)  

    When you hover over the name of that file, a tooltip will show you the exact URL it tried to load it from. 

    ---

    To take a guess, I'd say you try and return the image with a 'hardcoded' full url like (http://localhost/image01.png) but you're browsing the website to Sitefinity's projectmanager which operates not on port 80 but (in your screenshot 60876). If you let your .ashx return the images with a relative path (/image01.png) it should work better.

    But this is just a guess based on the previous postings.

    Jochem

  10. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    22 Mar 2012
    Link to this post
    Hi Hochem, Makus Berchtold and thank you for your help,
    The problem is that I  follow the same steps (I just remplace the Web form by a web user control ) but it doesn't work ! the RadRotator doesn't display the picturs .
    The website :
    http://www.mediafire.com/?i8njlpae8eei4bj
    The widget :
    http://www.mediafire.com/?x3cei3cydcu0il4
    Thank you again 

  11. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    22 Mar 2012
    Link to this post
    Dear Med

    Did you follow Jochems advice to see what is going on?

    ---------
    What is the path to the missing images.
    As an alternative to Jochems advice use fiddler2.com to see what is going on.

    Markus
  12. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    22 Mar 2012
    Link to this post
    Hi Mukus Berchtold,
    Yah of course, and I used Fiddler to,I have this error now : 
    403 Forbidden,
    So what should I do ?
    I attache a 
    screenshot  that show that.
    Thank you a lot  
  13. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    22 Mar 2012
    Link to this post
    Hello,
    I noticed that sitefinity change the Id,src and url of the images.
    I dont know why, and how to fixe that !
    And how can we do to make work on sitefinity a module that work greate on VS2010 ( a module that use a database)?
    I add the 2 screenshot that show that.
    Hop that the sitefinity admin help us to fixe that and progress and it w'll be usefull for many peoples who would like to used that .
    Thank you 


  14. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    22 Mar 2012
    Link to this post
    Hey Med,

    Sorry I haven't been able to try out the widget myself yet, but it seems that since you're not referencing the handler.ashx with a full url, Sitefinity tries to attach the path to it.

    Because the widget is in the /App_Data/ folder, you get the 403 error. I'm guessing if you make the image src="//Sitefinity/WebsiteTemplates/Theme01/WidgetTemplates/widget/Handler.ashx?Id=1" it should work. (Sitefinity automatically maps the /App_Data/Sitefinity to /Sitefinity).

    Another approach could be to move the handler.ashx from the widget folder to a folder outside of the /App_Data/... folderstructure.

    Good luck!
    Jochem
    Answered
  15. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    27 Mar 2012
    Link to this post
    Hi Jochem,
    Thank you so mutch for your help.
    I have change the Handler url in the widget.ascx and it doesn't work ( cause it dublicate the src url ) ,then I have put the widget files  (handler.ashx , widget.ascx , ...) outside App_Data (in the   sitefinity root project ) so I have got a url picture that doesn't existe in sitefinity project folder (ProAd/essaiwidget23/Action/../../Handler.ashx).
    I attache the pictur that explain that,
    Thank you so mutch 
  16. Med
    Med avatar
    22 posts
    Registered:
    19 Mar 2012
    27 Mar 2012
    Link to this post
    Hi jochem,Markus,
    Thank you so mutch for helping me.
    The widget work,I have got a Cs0433 error and I have solve it by put the db connection file outsite App_Data folder.
    Thankx again
    Med 
  17. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    27 Mar 2012
    Link to this post
    Hey Med,

    Glad you got it working and sorry it took so long


    Jochem
17 posts, 1 answered