[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1716
  • Last Modified:

SQL Connection using CommandType.StoredProcedure and SQLDataAdapter

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";
                  //comd.Parameters.Add("@ProgID",SqlDbType.VarChar,50);
                  sqlConn.Open();
                  SqlDataAdapter da = new SqlDataAdapter(comd);

                  //TEST
                  try
                  {
                        Dataset1 ds = new Dataset1();
                        da.Fill(ds);   //ERRORS HERE
                        oRpt.SetDataSource(ds);
                        CrystalReportViewer1.ReportSource = oRpt;
                  }
                  catch(Exception ex)
                  {
                        Response.Write(ex.Message.ToString());
                  }



Thanks!
0
GoldenJag
Asked:
GoldenJag
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sqlConn.Open();
SqlCommand comd=sqlConn.CreateCommand("sp_Test");  //??
comd.CommandType = CommandType.StoredProcedure;
//comd.Parameters.Add("@ProgID",SqlDbType.VarChar,50);
SqlDataAdapter da = new SqlDataAdapter(comd);

0
 
AGBrownCommented:
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.

Andy
0
 
GoldenJagAuthor Commented:
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");



0
 
GoldenJagAuthor Commented:
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).



0
 
AGBrownCommented:
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.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now