Microsoft Knowledge Base Email Alertz

KBAlertz.com: (824462) - If you use the SqlCeDataAdapter object to populate a DataSet object, and you do not explicitly call the Dispose method for all the associated SqlCeCommand instances, you may receive the following error message: Error Code: 8007000E Message: Not enough...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 824462 - Last Review: November 14, 2007 - Revision: 3.5

SqlCeCommand objects are not automatically disposed if you use a SqlCeDataAdapter object

SYMPTOMS

If you use the SqlCeDataAdapter object to populate a DataSet object, and you do not explicitly call the Dispose method for all the associated SqlCeCommand instances, you may receive the following error message:
Error Code: 8007000E
Message: Not enough storage is available to complete this operation.
Note The type of SqlCeCommand instances may be select, insert, update, or delete.

RESOLUTION

To resolve this problem, explicitly call the Dispose method for the SqlCeCommand instances when you use SqlCeCommand instances with a SqlCeDataAdapter object.

MORE INFORMATION

The following code sample shows how to populate a DataSet object with rows from a Microsoft SQL Server 2000 Windows CE Edition or Microsoft SQL Server 2005 Compact Edition database table by using a SelectCommand instance with the SqlCeDataAdapter object:
public static DataSet LoadData()
{
	string sqlstring = "";

	//  Make the connection to the SQL Server CE data source
	SqlCeConnection conn = new SqlCeConnection("Data Source=<completePath of SDF file>");

	//  Create the SqlCeDataAdapter object
	sqlCeDataAdapter da = new SqlCeDataAdapter();

	//  Create the DataSet object
	DataSet ds = new DataSet();

	try
	{
		sqlstring = "select name from mytable where name = ?";

		// Create the SelectCommand instance to run a select query
		da.SelectCommand = new SqlCeCommand();

		// Set SelectCommand object properties
		da.SelectCommand.Connection = conn;
        	da.SelectCommand.CommandText = sqlstring;
		da.SelectCommand.Parameters.Add(new  SqlCeParameter("name", System.Data.SqlDbType.NVarChar, 30));
		da.SelectCommand.Parameters["name"].Value = name;


		//  Populate the DataSet object
		da.Fill(ds,"name");
	}

	catch (SqlCeException sqlx)
	{
         	ShowErrors(sqlx);
	}

	catch (Exception x)
        {
		MessageBox.Show(x.Message.ToString());
	}

	finally
	{
		//  Explicitly dispose the SelectCommand instance
		da.SelectCommand.Dispose();

		da.Dispose();
	}

	return ds;
}
Note The SelectCommand instance is disposed by explicitly calling the Dispose method in the Finally block.

The following code sample provides a generic method that can be used to clean up all the command objects that are associated with the SqlCeDataAdapter object, such as SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand objects:
public System.Data.IDbDataAdapter DisposeAdapter (System.Data.IDbDataAdapter dbAdapter)
{
	if (dbAdapter is SqlCeDataAdapter)	
	{
		// Create the SqlCeCommand object and assign the SelectCommand object
		SqlCeCommand cmd = dbAdapter.SelectCommand;


		// Dispose the SqlCeCommand object
                if (cmd != null) 
                {
                    cmd.Dispose();
                }

                cmd = dbAdapter.InsertCommand;
                if (cmd != null) 
                {
                    cmd.Dispose();
                }

                cmd = dbAdapter.UpdateCommand;
                if (cmd != null) 
                {
                    cmd.Dispose();
                }

                cmd = dbAdapter.DeleteCommand; 
                if (cmd != null) 
                {
                    cmd.Dispose();
                }
	}

	return null;
}
Note The generic method in this sample accepts an object of type IDbDataAdapter as the input parameter, disposes the command objects that are associated with the IDbDataAdapter object, and then returns the resulting IDbDataAdapter object.

REFERENCES

For more information about using the SqlCeDataAdapter object to retrieve data from a SQL Server CE database, click the following article number to view the article in the Microsoft Knowledge Base:
813731  (http://kbalertz.com/Feedback.aspx?kbNumber=813731/ ) How to retrieve data from a SQL Server CE 2.0 database or from a SQL Server 2005 Compact Edition database and save the data in an XML document

APPLIES TO
  • Microsoft SQL Server 2000 Windows CE Edition 2.0
  • Microsoft SQL Server 2005 Compact Edition
Keywords: 
kbquery kbdatabase kbprb kbdataadapter kbappdev kbinfo kbcodesnippet KB824462
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please