More in this section

Forums / Developing with Sitefinity / Database keeps thinking it's local.

Database keeps thinking it's local.

4 posts, 0 answered
  1. Jason
    Jason avatar
    23 posts
    Registered:
    17 Jun 2009
    19 Jan 2010
    Link to this post
    Hi,

    I have a competition form user control installed on a website that writes the textbox data to a database.  The problem is that the database (or asp or sitefinity) keeps thinking it's local and give me this error:

    'c:\windows\system32\inetsrv\~\Custom\CompetitionForm\Database\websitePromoData.mdb' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.


    i did have the path set to ~/App_Data/websitePromoData.mdb but that cam back with the same results. 

    The snippet of code is as follows:


    This is the ascx code:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CompetitionForm.ascx.cs" 
        Inherits="CustomControls_CompetitionForm" %> 
    <%@ Register Assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
        Namespace="System.Web.DynamicData" TagPrefix="cc1" %> 
     
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Custom/CompetitionForm/Database/websitePromoData.mdb" 
        DeleteCommand="DELETE FROM [userDetails] WHERE (([email] = ?) OR ([email] IS NULL AND ? IS NULL))" 
        InsertCommand="INSERT INTO [userDetails] ([firstName], [lastName], [company], [email], [phone], [defaultQuestion], [otherQuestion], [industry]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" 
        SelectCommand="SELECT [firstName], [lastName], [company], [email], [phone], [defaultQuestion], [otherQuestion], [industry] FROM [userDetails]" 
        UpdateCommand="UPDATE [userDetails] SET [firstName] = ?, [lastName] = ?, [company] = ?, [phone] = ?, [defaultQuestion] = ?, [otherQuestion] = ?, [industry] = ? WHERE (([email] = ?) OR ([email] IS NULL AND ? IS NULL))"
        <DeleteParameters> 
            <asp:Parameter Name="email" Type="String" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="firstName" Type="String" /> 
            <asp:Parameter Name="lastName" Type="String" /> 
            <asp:Parameter Name="company" Type="String" /> 
            <asp:Parameter Name="phone" Type="String" /> 
            <asp:Parameter Name="defaultQuestion" Type="String" /> 
            <asp:Parameter Name="otherQuestion" Type="String" /> 
            <asp:Parameter Name="industry" Type="String" /> 
            <asp:Parameter Name="email" Type="String" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="firstName" Type="String" /> 
            <asp:Parameter Name="lastName" Type="String" /> 
            <asp:Parameter Name="company" Type="String" /> 
            <asp:Parameter Name="email" Type="String" /> 
            <asp:Parameter Name="phone" Type="String" /> 
            <asp:Parameter Name="defaultQuestion" Type="String" /> 
            <asp:Parameter Name="otherQuestion" Type="String" /> 
            <asp:Parameter Name="industry" Type="String" /> 
        </InsertParameters> 
    </asp:AccessDataSource> 

    And the code behind is:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Data.OleDb; 
    using System.Net.Mail; 
    using System.Net; 
     
    public partial class CustomControls_CompetitionForm : System.Web.UI.UserControl 
         
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
     
        protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e) 
        { 
            TextBox Email = (TextBox)FormView1.FindControl("txtEmail"); 
            String ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=~/Custom/CompetitionForm/Database/websitePromoData.mdb"
            OleDbConnection oConn = new OleDbConnection(ConnectionString); 
            String strSQL = "Select Count(email) as TheCount from userDetails where email =? "
            OleDbCommand cmd = new OleDbCommand(strSQL, oConn); 
            cmd.Parameters.AddWithValue("", Email.Text); 
            oConn.Open(); 
            int Result = (int)cmd.ExecuteScalar(); 
            if (Result > 0) 
            { 
                e.Cancel = true
                Label Duplicate = (Label)FindControl("lblValidate"); 
                Duplicate.Visible = true
                Duplicate.Text = "That email address has already been registered."
                CheckBox chkTerms = (CheckBox)FormView1.FindControl("chkTerms"); 
     
                if (chkTerms.Checked == false
                { 
                    Label Agreement = (Label)FindControl("lblValidate"); 
                    Agreement.Visible = true
                    Agreement.Text = "Please read and check Terms and Conditions."
                } 
            } 
            else 
            { 
                CheckBox chkTerms = (CheckBox)FormView1.FindControl("chkTerms"); 
     
                if (chkTerms.Checked == false
                { 
                    Label Agreement = (Label)FindControl("lblValidate"); 
                    Agreement.Visible = true
                    Agreement.Text = "Please read and check Terms and Conditions."
                    e.Cancel = true
                } 
                else if (chkTerms.Checked) 
                { 
                    Label Agreement = (Label)FindControl("lblValidate"); 
                    Agreement.Visible = false
                    Label Confirm = (Label)FindControl("lblConfirm"); 
                    Confirm.Visible = true
                    Send_Mail(); 
                    Confirm.Text = "Your entry has been processed.  A copy of your entry has been emailed to the address specified.  Thank you."
                } 
            } 
            oConn.Close(); 
       } 


    Your help (as always) is ver much appreciated, thank you.

    Jason
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Jan 2010
    Link to this post
    Hi Jason,

    Your path is not valid. You have to remove the Tilda, and this is what the error is saying.

    c:\windows\system32\inetsrv\~\Custom\CompetitionForm\Database\websitePromoData.mdb'

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jason
    Jason avatar
    23 posts
    Registered:
    17 Jun 2009
    19 Jan 2010
    Link to this post
    Thanks for your help Ivan,

    That produced the same error only his time without the tilda.

    'c:\Custom\CompetitionForm\Database\websitePromoData.mdb' is not a valid path.


    The page i'm viewing and entering data into is located on a web server but by this error it looks like it thinks it's on my computer.  I ge the same results viewing the page on my laptop and my kids computer also.

    Regards
    Jason
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Jan 2010
    Link to this post
    Hi Jason,


    The AccesDataSource  automatically generates the Connection string from the location of the .mdb file, which you feed to the DataFile property.The AccessDataSource control inherits the SqlDataSource class so you could try using SqlDataSource control instead.

    <asp:SqlDataSource ID="SqlDataSource1"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
        ProviderName="<%$ ConnectionStrings:MyConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM MyTable">
    </asp:SqlDataSource>


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered