SubSonic Forums
All Your Database Are Belong To Us

Error with SPs?

Latest post 11-18-2008 12:20 PM by stieferj. 14 replies.
  • 08-06-2008 1:39 PM

    Error with SPs?

    Hi, I have been using SubSonic for a little while, but I never used a stored procedure until now.

    I have a very weird behavior error

    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:

    Line 25: 
    Line 26:         SubSonic.StoredProcedure stpGetProjects = OmniAssitantDAL.SPs.GetProjects();
    Line 27:         System.Data.DataSet projects = stpGetProjects.GetDataSet();
    Line 28:         
    Line 29:         this.UltraWebGrid1.DataSource = projects;

     

    What's really weird is that if I place a breakpoint on line 27 and use the quickwatch to view the content of stpGetProjects and then run line 27 then everything runs correctly.

    Any idea what could be wrong here? Until I fix this, I can't use any stored procedure.

    Thanks alot

    Phil

  • 08-06-2008 2:41 PM In reply to

    Re: Error with SPs?

    Phil,

    On the face of it your code looks fine.  I just tried an example that approximates what you did and it works ok.  All my SPs have parameters, so I'll make one without and try it.  In the mean time...are you using a recent version 2.1?  Also, it might be helpful to add the subsonic project (source) to your solution so you can step through it.  I have been using this technique to help me to learn it.  It is good code to learn from.

     

  • 08-06-2008 3:07 PM In reply to

    Re: Error with SPs?

     Hey, that's exactly it. I created a dummy parameter and now everything works fine. Thing is that I'm not supposed to change the database and what I did was only for a test. Any resolution idea would be apreciated.

    My Subsonic DLL is 2.1.0.0 (Final)

    Phil

  • 08-06-2008 3:24 PM In reply to

    Re: Error with SPs?

    I created a dummy sproc like (MS SQL SERVER 2005):

    CREATE PROCEDURE DummyWithNoParms AS BEGIN SELECT 'JIM' END
    grant excute on DummyWithNoParms to public

    regenerated the classess  and it worked fine, so there is something else afoot.   Try the dummy sproc and see if that works.  If it does not, then some other difference is causing the problem.  We'll just have to eliminate them until we see what the matter is.

  • 08-08-2008 9:52 AM In reply to

    Re: Error with SPs?

     Hi all !

    I've got exactelly the same error with SPs and the SubSonic-2.1-Final.

    The error was : Object no set to a reference !

    at SubSonic.DataService.GetReader(QueryCommand cmd) in C:\svn\subsonicproject\trunk\SubSonic\DataProviders\DataService.cs:line 493
       at SubSonic.StoredProcedure.GetReader() in C:\svn\subsonicproject\trunk\SubSonic\ActiveRecord\StoredProcedure.cs:line 195
       at Admin_Default.LoadGraphics() in c:\Documents and Settings\Guillaume\Mes documents\Visual Studio 2005\Projects\EvalorhaSln\EvalorhaWeb\Default.aspx.cs:line 43
       at Admin_Default.PopulateControls() in c:\Documents and Settings\Guillaume\Mes documents\Visual Studio 2005\Projects\EvalorhaSln\EvalorhaWeb\Default.aspx.cs:line 72
       at Admin_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Guillaume\Mes documents\Visual Studio 2005\Projects\EvalorhaSln\EvalorhaWeb\Default.aspx.cs:line 25
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Then I rall back to SubSonic-2.1-RC1, and all things went good !

    Why do SubSonic-2.1-RC1 can call my SPs and not SubSonic-2.1-Final ?

    Thank you !

    Filed under:
  • 08-09-2008 1:26 PM In reply to

    • jaap
    • Not Ranked
    • Joined on 08-09-2008
    • Posts 1

    Re: Error with SPs?

     Hi,

    I'm experiencing the same problem in 2.1 final.

    The error only occurs for storedprocedures without a parameter. If I go into debug;

    SubSonic.

    StoredProcedure sp = new SubSonic.StoredProcedure("fetchlog", DataService.GetInstance("provider"), "");

    If immediately after I do sp.GetDataSet it throws a nullreferenceexception. If I just type sp (or something else, just to get sp evaluated) in the command view and after call GetDataSet it is ok....

  • 08-11-2008 12:02 PM In reply to

    Re: Error with SPs?

    I've also confirmed this as an issue.

    Chris

     

  • 08-11-2008 1:29 PM In reply to

    Re: Error with SPs?

    Yep, I'm having this problem too ever since I upgraded to 2.1 final. I have since rolled back to 2.1 rc 1 and that fixes the problem. All sprocs that have parameters work fine, it is only those without any parameters that are producing the error.

  • 08-11-2008 3:46 PM In reply to

    • rkery
    • Not Ranked
    • Joined on 08-11-2008
    • Posts 1

    Re: Error with SPs?

     I am having the same issues.  Is there a fix coming soon?

  • 08-13-2008 8:36 AM In reply to

    Re: Error with SPs?

    The issue seems to be that the inner sql command object for the stored procedure is only created when the Command property is accessed. 

    A work around is to simply access the property before calling Execute():

     

     

            public void ClearDownDataStore()
            {
                try
                {

                    // SubSonic.StoredProcedure sp = SPs.SProcClearDownDatabase();.Execute(); // Throws null reference exception
                    SubSonic.StoredProcedure sp = SPs.SProcClearDownDatabase();
                    if (sp.Command == null) throw new NullReferenceException("Stored Procedure command Is Null"); // ensure command is created
                    sp.Execute();
                }
                catch
                {
                    throw;
                }
            }

     

    So no dummy parameters necessary!

  • 08-29-2008 7:17 AM In reply to

    Re: Error with SPs?

     Yes - I'm also getting the same issue on upgrading to 2.1 Final.

    However the fix suggested doesn't work for me.  I tried accessing accessing other properties of the SP object first before calling .GetDataSet() - but not joy.

    e.g.

    String

    strTemp = sp.DisplayName;

    Sphengle

  • 08-29-2008 7:42 AM In reply to

    Re: Error with SPs?

     

    I have a solution...

    Get the stored procedure object...

    SubSonic.StoredProcedure sp = SPs.Blah();

    string dummy = sp.Command.CommandSql;

    DataSet ds = sp.GetDataSet();

    It's something to do with the deep-loading.  (Thanks to my colleague)

    Sphengle

     

  • 11-04-2008 2:24 PM In reply to

    Re: Error with SPs?

     I also ran into this problem with version 2.1 Final.  Sphengle's solution worked for me.

    Thanks Sphengle!

  • 11-13-2008 10:23 AM In reply to

    • Adrian
    • Not Ranked
    • Joined on 10-02-2008
    • Posts 1

    Re: Error with SPs?

    I came across this problem calling a sproc with no parameters and the following sorted it for me, I'm calling sp.GetReader()

    Thanks all for posting.

    mcjarvis:

    [snip]
                    if (sp.Command == null) throw new NullReferenceException("Stored Procedure command Is Null"); // ensure command is created
                    sp.Execute();
    [snip]

     

  • 11-18-2008 12:20 PM In reply to

    Re: Error with SPs?

    My solution deals with modifying the Subsonic source code. This is pretty easy to do, took me less then 5 mins. This is really useful if you have more then 2 stored proc's that don't take arguments.

    http://www.jasonstiefer.com/blog/post/2008/11/SubSonic-with-Stored-Procs.aspx

Page 1 of 1 (15 items) | RSS