OutOfMemoryException after loading System.Data.SqlServerCe

A

artheseus

Hello,

My application is running on a HP iPaq 614c with WM6. I'm running out
of memory just few lines after my application start to initialize.
there is really no resources used at this point, no image loaded, no
forms created, no database connections, no remote
connection...nothing...my application barely got itself initialized at
this point.

What got my attention was that my application never being able to load
the images that were taken with the build-in camera. My first thought
was, maybe the bitmap format is not supported, with proved to not be
true. What I did:

1. Debug my application and stopped it at breakpoint just before
System.Data.SqlServerCe is loaded. (this is a call to a method of a
singleton class that represents the unique connection open to the
local based and it's localized in a DLL that is a project within my
solution)
2. Use the immediate window to load and dispose Bitmaps.

I can load and dispose the same bitmap several times and nothing bad
happens (no OutOfMemoryException at all). But after the
System.Data.SqlServerCe is loaded I get an OutOfMemoryException on my
first attempt to load the same bitmap that was using for tests before.
The SqlCeConnection object is not even created at this point.

I'm totally lost here, any ideas?

TIA,
Arth
 
S

Simon Hart [MVP]

It's difficult to say without some code. Could you please post some code for
us to see.
 
A

artheseus

It's very simple could in fact that is why I didn't post it. Sorry
some names and comments are in portuguese.

Here is my Wrapper/Singleton for the data base connection: (this code
is in "MyDBApi.dll")

/// <summary>
/// Classe que implementa a interface de conexão com banco SQL CE
/// </summary>
public sealed class Conexao : Singleton<Conexao> {
#region Atributos e Propriedades
private System.Data.IDbConnection _dbConnection;
/// <summary>
/// Conexão com o banco de dados
/// </summary>
public System.Data.IDbConnection DbConnection {
get { return _dbConnection; }
set { _dbConnection = value; }
}
#endregion

public Conexao() {
}

#region Métodos de conexão com o banco de dados
/// <summary>
/// Cria o objeto de conexao com o banco de dados
/// </summary>
/// <param name="connString"></param>
public void Inicializar(string connString) {
_dbConnection = new System.Data.SqlServerCe.SqlCeConnection
(connString);
}
#endregion
}

Here is my Program.cs: (this code is in "Application.exe")

/// <summary>
/// The main entry point for the application.
/// </summary>
[System.MTAThread]
static void Main() {
try {
using (ControladorGeral ctrl = new ControladorGeral())
ctrl.Executar();
} catch (System.Exception ex) {
Log4CS.Error(ex);
ControladorErro.Mostrar(ex);
}
}

This is the Executar() called above: (this code is in
"Application.exe", I comment out some code and still get the
exception)

public override ResultadoForm Executar() {
//ConfigLogging();
//DesligaWarning();

ControladorBase ctrlAtual = null;

try {
//Log4CS.Info("[ControladorGeral] Versão rodando: " +
ControladorLogin.GetVersaoAplicativo());

//VerificaBaseTeste();

// Breakpoint on line below, after executing this line the
OutOfMemoryException start happening when I try to load a jpg file
// Something like Bitmap bmp = new Bitmap("image.jpg"); fails
after executing this line, but works fine before I execute it
Conexao.Instancia.Inicializar(Queries.ConnectionString);
Conexao.Instancia.DbConnection.Open();

// ...
} finally {
if (ctrlAtual != null) {
ctrlAtual.Dispose();
ctrlAtual = null;
}

Conexao.Instancia.DbConnection.Close();
}

return ResultadoForm.Nenhum;
}
 
A

artheseus

I also tried to create the connection object inside the EXE replacing
the line of the breakpoint with this code:

Conexao.Instancia.DbConnection = new
System.Data.SqlServerCe.SqlCeConnection(Queries.ConnectionString);

Right when I enter method Executar() SqlCeServer.dll gets loaded and I
start getting the OutOfMemoryException on every jpg image I try to
load

It's very simple could in fact that is why I didn't post it. Sorry
some names and comments are in portuguese.

Here is my Wrapper/Singleton for the data base connection: (this code
is in "MyDBApi.dll")

        /// <summary>
        /// Classe que implementa a interface de conexão com banco SQL CE
        /// </summary>
        public sealed class Conexao : Singleton<Conexao> {
                #region Atributos e Propriedades
                private System.Data.IDbConnection _dbConnection;
                /// <summary>
                /// Conexão com o banco de dados
                /// </summary>
                public System.Data.IDbConnection DbConnection {
                        get { return _dbConnection; }
                        set { _dbConnection = value; }
                }
                #endregion

                public Conexao() {
                }

                #region Métodos de conexão com o banco de dados
                /// <summary>
                /// Cria o objeto de conexao com o banco de dados
                /// </summary>
                /// <param name="connString"></param>
                public void Inicializar(string connString) {
                        _dbConnection = new System.Data.SqlServerCe.SqlCeConnection
(connString);
                }
                #endregion
        }

Here is my Program.cs: (this code is in "Application.exe")

                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [System.MTAThread]
                static void Main() {
                        try {
                                using (ControladorGeral ctrl = new ControladorGeral())
                                        ctrl.Executar();
                        } catch (System.Exceptionex) {
                                Log4CS.Error(ex);
                                ControladorErro.Mostrar(ex);
                        }
                }

This is the Executar() called above: (this code is in
"Application.exe", I comment out some code and still get the
exception)

                public override ResultadoForm Executar() {
                        //ConfigLogging();
                        //DesligaWarning();

                        ControladorBase ctrlAtual= null;

                        try {
                                //Log4CS.Info("[ControladorGeral] Versão rodando: " +
ControladorLogin.GetVersaoAplicativo());

                                //VerificaBaseTeste();

                                // Breakpoint on line below, after executing this line the
OutOfMemoryException start happening when I try to load a jpg file
                                // Something like Bitmap bmp = new Bitmap("image.jpg"); fails
after executing this line, but works fine before I execute it
                                Conexao.Instancia.Inicializar(Queries.ConnectionString);
                                Conexao.Instancia.DbConnection.Open();

                                // ...
                        } finally {
                                if (ctrlAtual != null) {
                                        ctrlAtual.Dispose();
                                        ctrlAtual = null;
                                }

                                Conexao.Instancia.DbConnection.Close();
                        }

                        return ResultadoForm.Nenhum;
                }

It's difficult to say without some code. Could you please post some code for
us to see.
 
A

artheseus

I also tried to create the connection object inside the EXE replacing
the line of the breakpoint with this code:

Conexao.Instancia.DbConnection = new
System.Data.SqlServerCe.SqlCeConnection(Queries.ConnectionString);

Right when I enter method Executar() SqlCeServer.dll gets loaded and I
start getting the OutOfMemoryException on every jpg image I try to
load

It's very simple could in fact that is why I didn't post it. Sorry
some names and comments are in portuguese.

Here is my Wrapper/Singleton for the data base connection: (this code
is in "MyDBApi.dll")

        /// <summary>
        /// Classe que implementa a interface de conexão com banco SQL CE
        /// </summary>
        public sealed class Conexao : Singleton<Conexao> {
                #region Atributos e Propriedades
                private System.Data.IDbConnection _dbConnection;
                /// <summary>
                /// Conexão com o banco de dados
                /// </summary>
                public System.Data.IDbConnection DbConnection {
                        get { return _dbConnection; }
                        set { _dbConnection = value; }
                }
                #endregion

                public Conexao() {
                }

                #region Métodos de conexão com o banco de dados
                /// <summary>
                /// Cria o objeto de conexao com o banco de dados
                /// </summary>
                /// <param name="connString"></param>
                public void Inicializar(string connString) {
                        _dbConnection = new System.Data.SqlServerCe.SqlCeConnection
(connString);
                }
                #endregion
        }

Here is my Program.cs: (this code is in "Application.exe")

                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [System.MTAThread]
                static void Main() {
                        try {
                                using (ControladorGeral ctrl = new ControladorGeral())
                                        ctrl.Executar();
                        } catch (System.Exceptionex) {
                                Log4CS.Error(ex);
                                ControladorErro.Mostrar(ex);
                        }
                }

This is the Executar() called above: (this code is in
"Application.exe", I comment out some code and still get the
exception)

                public override ResultadoForm Executar() {
                        //ConfigLogging();
                        //DesligaWarning();

                        ControladorBase ctrlAtual= null;

                        try {
                                //Log4CS.Info("[ControladorGeral] Versão rodando: " +
ControladorLogin.GetVersaoAplicativo());

                                //VerificaBaseTeste();

                                // Breakpoint on line below, after executing this line the
OutOfMemoryException start happening when I try to load a jpg file
                                // Something like Bitmap bmp = new Bitmap("image.jpg"); fails
after executing this line, but works fine before I execute it
                                Conexao.Instancia.Inicializar(Queries.ConnectionString);
                                Conexao.Instancia.DbConnection.Open();

                                // ...
                        } finally {
                                if (ctrlAtual != null) {
                                        ctrlAtual.Dispose();
                                        ctrlAtual = null;
                                }

                                Conexao.Instancia.DbConnection.Close();
                        }

                        return ResultadoForm.Nenhum;
                }

It's difficult to say without some code. Could you please post some code for
us to see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top