Re: Native exception 0xc0000005 when using SQLCE and .NET CF 2.0?!



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)=&

.



Relevant Pages

  • Re: CREATE AGGREGATE failed because type Concatenate does not conform to UDAGG specification due to
    ... Go to the Database tab and click on the browse button next to the connection string. ... In the New Database Reference dialog, enter the details for the database where you want to deploy the assembly and create the user defined aggregate. ... I'm trying to do some CLR integration with sql server 2005. ...
    (microsoft.public.sqlserver.programming)
  • Re: return multiple rows from sql statement
    ... Concatening SQL ... strings from input values is almost certainly a safe path to SQL ... All characters that are entered in the fields make their way into the database unaltered. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)
  • Re: Establish connection with and transferring data to Access
    ... If you Google for SQL +"Insert into" you'll a dozen tutorials. ... The specific problem with your code is that you need to quote string ... Dim vConnection As New ADODB.Connection ... Doug's code opens and writes to an existing database. ...
    (microsoft.public.word.vba.general)
  • Re: Random Access Files in databases
    ... I am not a Database design guru either, but it might be wise to break ... location and read in in the string, and then you want to get an integer, so ... I'm pretty sure the SQL language does have ways to seek around in BLOB ... some SQL purist are quick to point out that MySQL doesn't implement the SQL ...
    (comp.lang.java.programmer)
  • Problems Setting Up Database
    ... I seem to be having errors creating and accessing an SQL database. ... New SQL Server Database'. ... System.Web.Management.SqlServices.ExecuteFile(String file, String server, ...
    (microsoft.public.dotnet.framework.aspnet)

Loading