SQL Connection using CommandType.StoredProcedure and SQLDataAdapter

Posted on 2006-05-08
Last Modified: 2010-07-27
I am new to .NET so any advice is welcomed.  Can someone tell me what i am doing wrong in this segment of code.

I am trying to run a Crystal Report and I have defined a Dataset1.xsd in my project.  I am not sure if i am doing the comd.Connection correctly. but i get an error (on line  "da.Fill(ds);  " that says:

Can someone help me with this.

{"Load report failed." }
    System.Object: {System.Exception}
    _className: null
    _COMPlusExceptionCode: -532459699
    _exceptionMethod: <undefined value>
    _exceptionMethodString: null
    _helpURL: null
    _HResult: -2146233088
    _innerException: {"Not enough memory for operation." }
SqlConnection sqlConn = new SqlConnection(pm.connection);
                  SqlCommand comd=sqlConn.CreateCommand();  //??

                  comd = new SqlCommand();
                  comd.Connection = sqlConn;
                  comd.CommandType = CommandType.StoredProcedure;
                  comd.CommandText = "sp_Test";
                  SqlDataAdapter da = new SqlDataAdapter(comd);

                        Dataset1 ds = new Dataset1();
                        da.Fill(ds);   //ERRORS HERE
                        CrystalReportViewer1.ReportSource = oRpt;
                  catch(Exception ex)

Question by:GoldenJag
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    SqlCommand comd=sqlConn.CreateCommand("sp_Test");  //??
    comd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapter(comd);

    LVL 12

    Accepted Solution

    Your code is fine, you can create your command object either with the sqlConn.CreateCommand, or by doing new SqlCommand() and then setting the comd.Connection property to sqlConn. As you have it you will have no problems.

    You don't actually need to open the connection (and in fact shouldn't, as a best practice) until just before the fill. As another pointer, you should ensure that you always, always, close your sqlconnection before it goes out of scope. So your try/catch should be structured with a finally{sqlConn.Close()} if that is appropriate for your code.

    So I don't think this error is anything to do with your connection and command. A couple of questions:
    1) which versions of .NET, crystal and Visual Studio do you use?
    2) Is that error on the da.Fill(ds) line, or the SetDataSource or ReportSource lines? I only ask as the error says "Load Report Failed" which wouldn't seem to relate to da.Fill, and there are a lot of web search results for "Load report failed." "Not enough memory for operation." which all refer to Crystal reports.


    Author Comment

    I am using MS C# Development Environment 2003 version 7.1.3088 (Visual Studio 6.0)
    MS.Net Framework 1.1 version 4322 SP1, Crystal XI.

    The program errors here:   da.Fill(ds);   //ERRORS HERE
    the error also occurs when i use da.Fill(ds,"TableName");


    Author Comment

    I am sorry guys. i gave you wrong info about where program errored.

    It errored at : oRpt.SetDataSource(ds); and not at the da.Fill(ds).

    LVL 12

    Expert Comment

    This is definitely a Crystal problem then, I think there is a business objects hotfix for it, though I haven't come across this problem myself or had the need to test the hotfix.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now