Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- From: Jin <jinsoochang@xxxxxxxxx>
- Date: Wed, 03 Oct 2007 18:24:09 -0000
On Oct 2, 11:10 am, An o' Neamus <onea...@xxxxxxxxx> wrote:
Greetings,
I have written a very basic C# console test app to check the
performance and reliability of SQLCE on Windows CE 5.0 (source code
below). Running this on different Windows CE 5.0 devices, I always get
a 0xc0000005 native exception error when reaching 25592 inserts. It
doesn't matter whether the database is empty or not when the test is
run, it always fails at that exact number of inserts. Given that I
would expect a managed application not to be able to generate native
exceptions anyway, and can't really see any reason why it would in
this case, I'm at a bit of a loss as to what's going wrong... Any
ideas?
Using:
VS2005 w/ SP1
Windows CE 5.0 (on custom SH4 platform and HTC WM5 smartphone)
.NET CF 2.0 w/ SP1 and post SP1 patch
SQLCE 3.0.3600.0
TIA
Source code:
using System.Data;
using System.Data.SqlServerCe;
namespace TestDB
{
class Program
{
static void Main(string[] args)
{
SqlCeConnection sqlConnection = new SqlCeConnection();
SqlCeCommand sqlCommand = sqlConnection.CreateCommand();
SqlCeResultSet sqlResult;
string strDatabase = "\\TestDB.sdf";
string strTable = "TestTable";
try
{
// Database connection string
sqlConnection.ConnectionString =
"Data Source=" + strDatabase;
// Database file doesn't exist?
if (!System.IO.File.Exists( strDatabase ))
{
// Create SQL engine object
SqlCeEngine sqlEngine = new SqlCeEngine(
sqlConnection.ConnectionString);
Console.WriteLine("Creating database: " +
strDatabase);
// Use it to create database
sqlEngine.CreateDatabase();
}
Console.WriteLine("Opening database: " + strDatabase);
// Open database connection
sqlConnection.Open();
// Display SQL version
Console.WriteLine("SQL Version: "
+ sqlConnection.ServerVersion.ToString());
// Check if table exists
sqlCommand.CommandText = "SELECT TABLE_NAME FROM "
+ "INFORMATION_SCHEMA.TABLES WHERE "
+ "TABLE_NAME = '" + strTable + "'";
sqlResult = sqlCommand.ExecuteResultSet(
ResultSetOptions.Insensitive);
// Table doesn't exist?
if (!sqlResult.Read())
{
Console.WriteLine("Creating table: " + strTable);
// Create table
sqlCommand.CommandText = "CREATE TABLE " +
strTable
+ "(Sequence integer IDENTITY(1,1) NOT NULL
PRIMARY KEY, "
+ "Timestamp datetime DEFAULT GETDATE(),"
+ "Message nvarchar(80))";
sqlCommand.ExecuteNonQuery();
}
string strText;
for (int i = 1; i <= 500000; i++)
{
Console.Write("\rInserted " + i.ToString() + "
records ");
strText = "Row Number: " + i.ToString();
sqlCommand.CommandText = "INSERT INTO " + strTable
+ " (Message) VALUES ('" + strText + "')";
sqlCommand.ExecuteNonQuery();
}
}
// SQL error
catch(SqlCeException sqlex)
{
// Display all error messages
Console.WriteLine( "ERROR:" );
foreach (SqlCeError sqlError in sqlex.Errors)
{
Console.WriteLine( sqlError );
}
}
// Other errors
catch(Exception ex)
{
// Display error message
Console.WriteLine( "ERROR:" );
Console.WriteLine( ex.Message );
}
finally
{
// Close connection
if (sqlConnection.State != ConnectionState.Closed)
{
Console.WriteLine("Closing database");
sqlConnection.Close();
}
}
Console.ReadLine();
}
}
}
It's odd that it's failing at that exact number of inserts. It may or
may not be the cause, but here are two suggestions:
1. In your connect string, define a larger Buffer Size: i.e. "Max
Buffer Size = 2048"
2. Since you're building a new SQL Insert string each time, you may
be running out of memory. Instead of using the "string" object, try
using the StringBuilder instead. It's far more efficient in terms of
memory usage.
Finally, see if the following helps in terms of insert performance:
http://www.pocketpcdn.com/print/articles/?&atb.set(c_id)=74&atb.set(a_id)=11003&atb.perform(details)=&
.
- Follow-Ups:
- Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- From: An o' Neamus
- Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- References:
- Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- From: An o' Neamus
- Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- Prev by Date: Re: Massive insert
- Next by Date: Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- Previous by thread: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- Next by thread: Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!
- Index(es):
Relevant Pages
|
Loading