DataSourceControl Problem

Last post 03-24-2009 11:07 AM by egraffius. 3 replies.

Sort Posts:

  • Crying [:'(] DataSourceControl Problem

    03-18-2009, 9:15 PM
    • Member
      17 point Member
    • egraffius
    • Member since 08-22-2008, 11:34 PM
    • Georgia
    • Posts 23

    I had this page in my application working, but I requested my host company to move me to a new server where I can have remote DB access.  All I should have had to do was change the connection string in the web.config. I am not sure if it is the code or the server. (Same setup: IIS7 .Net3.5 MSSQL 2005)  Here is the code and the error page:

     ***********************************************ASPX***************************************************************
    <%@ Page Language="C#" MasterPageFile="~/GNPM.Master" AutoEventWireup="true" CodeFile="ViewQuotes.aspx.cs" Inherits="GNP_Machining.Secure_Admin.WebForm2" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="quote_no"
    DataSourceID="ObjectDataSource1">
    <Columns>
    <asp:TemplateField HeaderText="Quote Number" InsertVisible="False"
    SortExpression="quote_no">
    <EditItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("quote_no") %>'></asp:Label>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:HyperLink ID="ViewURL" runat="server" NavigateUrl='<%# FormatUrl( (int) Eval("quote_no") ) %>' Text = '<%# Eval("quote_no") %>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="create_datetime" HeaderText="Date"
    SortExpression="create_datetime" />
    <asp:BoundField DataField="update_user_id" HeaderText="User"
    SortExpression="update_user_id" />
    </Columns>
    <HeaderStyle BackColor="#355532" ForeColor="White" />
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    DeleteMethod="Delete" InsertMethod="Insert"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
    TypeName="Quote_Data_DatasetTableAdapters.Quote_FileTableAdapter"
    UpdateMethod="Update">
    <DeleteParameters>
    <asp:Parameter Name="Original_quote_no" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
    <asp:Parameter Name="user_id" Type="Object" />
    <asp:Parameter Name="part_no" Type="String" />
    <asp:Parameter Name="qty" Type="Int32" />
    <asp:Parameter Name="est_due_date" Type="DateTime" />
    <asp:Parameter Name="material_specs" Type="String" />
    <asp:Parameter Name="instructions" Type="String" />
    <asp:Parameter Name="create_user_id" Type="String" />
    <asp:Parameter Name="create_datetime" Type="DateTime" />
    <asp:Parameter Name="update_user_id" Type="String" />
    <asp:Parameter Name="update_datetime" Type="DateTime" />
    <asp:Parameter Name="Original_quote_no" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
    <asp:Parameter Name="user_id" Type="Object" />
    <asp:Parameter Name="part_no" Type="String" />
    <asp:Parameter Name="qty" Type="Int32" />
    <asp:Parameter Name="est_due_date" Type="DateTime" />
    <asp:Parameter Name="material_specs" Type="String" />
    <asp:Parameter Name="instructions" Type="String" />
    <asp:Parameter Name="create_user_id" Type="String" />
    <asp:Parameter Name="create_datetime" Type="DateTime" />
    <asp:Parameter Name="update_user_id" Type="String" />
    <asp:Parameter Name="update_datetime" Type="DateTime" />
    </InsertParameters>
    </asp:ObjectDataSource>
    </
    asp:Content>

    ***********************************************CodeBehind*********************************************************
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;

    namespace GNP_Machining.Secure_Admin

    {

    public partial class WebForm2 : System.Web.UI.Page

    {

     

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)

    {

    SqlDataSource DataSource =(SqlDataSource)Page.FindControl("ObjectDataSource1");

     

    }

    }

    protected string FormatUrl(int quote_no)

    {

    if (quote_no < 1)

    throw new ArgumentOutOfRangeException("quote_no");

    return "ViewQuoteFiles.aspx?quote_no=" + quote_no;

    }

    }

    }

    ***********************************************Error Page***********************************************************

    Object reference not set to an instance of an object.

    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.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Quote_Data_DatasetTableAdapters.Quote_FileTableAdapter.InitConnection() +56
       Quote_Data_DatasetTableAdapters.Quote_FileTableAdapter.InitAdapter() +462
       Quote_Data_DatasetTableAdapters.Quote_FileTableAdapter.GetData() +22
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
       System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +308
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
       System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
       System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
       System.Web.UI.WebControls.GridView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +50
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
    

  • Re: DataSourceControl Problem

    03-19-2009, 3:31 AM
    • Participant
      1,625 point Participant
    • asifchouhan
    • Member since 02-13-2009, 10:04 AM
    • India
    • Posts 295

     why you want to do this

    Page.FindControl("ObjectDataSource1"); // since you are on same page no need of finding control objectdatasource.

    see the error code it has error on this control only

       System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960
     
    Regards 
     Asif
     If your problem is solved. Mark it as "ANSWER" 
     

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: DataSourceControl Problem

    03-23-2009, 2:47 AM
    Answer

    Hi egraffius ,

    egraffius:
    I am not sure if it is the code or the server.

    egraffius:
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    DeleteMethod="Delete" InsertMethod="Insert"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
    TypeName="Quote_Data_DatasetTableAdapters.Quote_FileTableAdapter"
    UpdateMethod="Update">

    I notice you connect the objectdatasource to a tableadapter which manipulate a strong typed datatable, so you need to change tableadapter's connectstirng :
    On the designer window, right click on the TableAdapter section, select Properties. In the properties window expand the Connection and change it's value.

    Or you can change it at codebehind: http://kmccaa.blogspot.com/2007/07/how-to-move-typed-dataset-to-its-own_11.html

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Re: DataSourceControl Problem

    03-24-2009, 11:07 AM
    • Member
      17 point Member
    • egraffius
    • Member since 08-22-2008, 11:34 PM
    • Georgia
    • Posts 23

    Samu,

     you are very observant, that is exactly what casused the problem.  I had an old conection string in my web.config that I deleted thinking I was not using it anymore.  I forgot that it was being used by the table adapter.  I updated the table adapter to use the new connection string and it worked.  Thanks everyone for your help in this. I hope anyone else having a similar problem can use this post in the future to troubleshoot their app.

Page 1 of 1 (4 items)