Announcement

Collapse
No announcement yet.

openfiledialog sql compact framework error

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • openfiledialog sql compact framework error

    hi @ all,

    ich habe ein picturebox wo bei onclick ein filedialog geöffnet werden soll.. die picturebox wurde vorher mit einem bild aus der datenbank gefüttert.. klickt man nun während der laufzeit auf die picturebox erscheint folgender fehler:

    Exceptioncode: 0xc0000005
    .
    .
    .
    Faulting module sqlcese35.dll

    at
    NaativeMethods.SafeRelease(IntPtr& ppUnknown)
    at
    SQLCEDataReader.ReleaseNativeInterfaces()
    at
    SQLCEDataReader.Dispose(Boolean disposing)
    at
    SQLCEDataReader.Finalize()


    .. ich denke ja der fehler liegt in meiner datenbank klasse, das die connection nicht richtig geschlossen wird oder so.. vllt kann sich das jemand anschauen^^.. hier die relvanten methoden der datenbank
    Code:
    public CDatabase()
            {
                try
                {
                    //default image in byte array laden
                    string defPhotoPath = @"\Program Files\img\default.jpg";
    
                    FileStream fsToReadImage = new FileStream(defPhotoPath, FileMode.Open, FileAccess.Read);
    	            BinaryReader brForTheImage = new BinaryReader(fsToReadImage);
                    this.defaultPhoto = brForTheImage.ReadBytes((int)fsToReadImage.Length);
                }
                catch (IOException e)
                {
                    MessageBox.Show(e.Message);
                }
                finally
                {
                   
                }
                
            }
    
    public void init()
            {         
                try
                {
                    if (File.Exists(DBFILENAME))
                    {
                        File.Delete(DBFILENAME);
                    }
    
                    // Create database
                    SqlCeEngine engine = new SqlCeEngine(getConnectionString());
                    engine.CreateDatabase();
    
                    // Create table tAddress 
                    executeQuery(SQL_CREATE_TABLE_TADDRESS);
    
                    // Create table tPatient table
                    executeQuery(SQL_CREATE_TABLE_TPATIENT);
    
                    // Add sample data
                    addTestPatients();      
                }
                catch (SqlCeException sqlexception)
                {
                    MessageBox.Show(sqlexception.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    dbConnection.Close();
                }                     
            }
    
    
    
    public CPerson getPerson(int id)
            {
                CPerson person = new CPerson();
    
                SqlCeResultSet rs = executeQuery("SELECT PK_PatientId, Prename, Surname, Birthname, Birthdate FROM tPatient WHERE PK_PatientId = " + Convert.ToString(id) + " ORDER BY Surname ASC");
    
                if (rs.HasRows)
                {
                    int ordId = rs.GetOrdinal("PK_PatientId");
                    int ordPrename = rs.GetOrdinal("Prename");
                    int ordSurname = rs.GetOrdinal("Surname");
                    int ordBirthname = rs.GetOrdinal("Birthname");
                    int ordBirthdate = rs.GetOrdinal("Birthdate");
                    // Read first row
                    rs.ReadFirst();
    
                    dbConnection = new SqlCeConnection(getConnectionString());
    
                    if (dbConnection.State == ConnectionState.Closed)
                    {
                        dbConnection.Open();
                    }
    
                    SqlCeCommand cmd = new SqlCeCommand("SELECT Photo FROM tPatient WHERE PK_PatientId = " + Convert.ToString(id), dbConnection); 
                    byte[] file = (byte[])cmd.ExecuteScalar();
    
                    MemoryStream ms = new MemoryStream(file);
                    Bitmap photo = new Bitmap(ms);
    
                    person.set(rs.GetInt32(ordId),
                               rs.GetString(ordPrename),
                               rs.GetString(ordSurname),
                               rs.GetString(ordBirthname),
                               rs.GetString(ordBirthdate),
                               photo);
                }
    
                dbConnection.Close();
    
                return person;
    
     private SqlCeResultSet executeQuery(string query)
            {
                SqlCeResultSet rs = null;
    
                dbConnection = new SqlCeConnection(getConnectionString());
    
                try
                {
                    if (dbConnection.State == ConnectionState.Closed)
                    {
                        dbConnection.Open();
                    }
    
                    SqlCeCommand cmd = new SqlCeCommand(query, dbConnection);
    
                    cmd.CommandType = CommandType.Text;
    
                    rs = cmd.ExecuteResultSet(ResultSetOptions.Scrollable);
    
                }catch (SqlCeException sqlexception)
                {
                    MessageBox.Show(sqlexception.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    //TODO CLOSE CONNECTION
                    //dbConnection.Close();
                }
    
                return rs;
            }
    
    
    .. und die onclick fkt.
    
    
    private void tabPageInfoPhotoPbPic_Click(object sender, EventArgs e)
            {
                OpenFileDialog filedlg = new OpenFileDialog();
                if (filedlg.ShowDialog() == DialogResult.OK)         
                {             
            
                }
            }           }
    Ja auch den fehler zugoogln half mir nichgt weiter.. ich hoffe hier hat wieder jemand rat für mich

  • #2
    OK problem gelösst nach dezenten 5h (min) googlen und debuggen

    Für alle die den selben Fehler haben: meine erste vermutung hat sich bestätigt: ich hatte einfach vergessen das resultset was executeQuery zurückgibt auch wieder zu schließen mit: überaschung rs.Close() .. nun denn, schön tag noch^^

    Comment


    • #3
      FileStream fsToReadImage

      ...wird auch nicht geschlossen
      Christian

      Comment

      Working...
      X