Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Destroying database object

Destroying database object

Scheduled Pinned Locked Moved Database
questiondatabasemysql
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jose Luis Sogorb
    wrote on last edited by
    #1

    I close a database using: database.OpenEx(mySql,CDatabase::noOdbcDialog) ... ...more code... database.Close(); but it remains existing. I have read it is also needed to destroy the object,, how can I do it? Thanks.

    I 1 Reply Last reply
    0
    • J Jose Luis Sogorb

      I close a database using: database.OpenEx(mySql,CDatabase::noOdbcDialog) ... ...more code... database.Close(); but it remains existing. I have read it is also needed to destroy the object,, how can I do it? Thanks.

      I Offline
      I Offline
      ian mariano
      wrote on last edited by
      #2

      Set database = Nothing (in straight asp)

      "The greatest danger to humanity is humanity without an open mind."
        - Ian Mariano - http://www.ian-space.com/

      J 1 Reply Last reply
      0
      • I ian mariano

        Set database = Nothing (in straight asp)

        "The greatest danger to humanity is humanity without an open mind."
          - Ian Mariano - http://www.ian-space.com/

        J Offline
        J Offline
        Jose Luis Sogorb
        wrote on last edited by
        #3

        Well, it is an MFC app, this way: void OnExcel(CString sExcelFile)//, CString ficheroSolo) { CDatabase database; CString sDriver ;//= "MICROSOFT EXCEL DRIVER (*.XLS)"; sDriver = GetExcelDriver(); CString sSql; TRY { // Build the creation string for access without DSN sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver, sExcelFile, sExcelFile); // Create the database (i.e. Excel sheet) if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { // Create table structure sSql.Format( "CREATE TABLE Graficas (Fecha TEXT, Hora NUMBER,[Temperatura (ºC)] NUMBER,[Rocío (ºC)] NUMBER,[Presión (mb)] NUMBER,[Velocidad (km/h)] NUMBER,[Dirección (º)] NUMBER,Brújula TEXT)"); database.ExecuteSQL(sSql); } ...more code ...INSERT INTO, etc .... database.Close();

        I 1 Reply Last reply
        0
        • J Jose Luis Sogorb

          Well, it is an MFC app, this way: void OnExcel(CString sExcelFile)//, CString ficheroSolo) { CDatabase database; CString sDriver ;//= "MICROSOFT EXCEL DRIVER (*.XLS)"; sDriver = GetExcelDriver(); CString sSql; TRY { // Build the creation string for access without DSN sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver, sExcelFile, sExcelFile); // Create the database (i.e. Excel sheet) if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { // Create table structure sSql.Format( "CREATE TABLE Graficas (Fecha TEXT, Hora NUMBER,[Temperatura (ºC)] NUMBER,[Rocío (ºC)] NUMBER,[Presión (mb)] NUMBER,[Velocidad (km/h)] NUMBER,[Dirección (º)] NUMBER,Brújula TEXT)"); database.ExecuteSQL(sSql); } ...more code ...INSERT INTO, etc .... database.Close();

          I Offline
          I Offline
          ian mariano
          wrote on last edited by
          #4

          When the your function ends, the CDatabase object is destroyed because it passes out of scope. There's no need to destroy it yourself, unless you created it with new, in which case you'll have to delete it.

          "The greatest danger to humanity is humanity without an open mind."
            - Ian Mariano - http://www.ian-space.com/

          J 1 Reply Last reply
          0
          • I ian mariano

            When the your function ends, the CDatabase object is destroyed because it passes out of scope. There's no need to destroy it yourself, unless you created it with new, in which case you'll have to delete it.

            "The greatest danger to humanity is humanity without an open mind."
              - Ian Mariano - http://www.ian-space.com/

            J Offline
            J Offline
            Jose Luis Sogorb
            wrote on last edited by
            #5

            Ok, ok. You're right. It was my mistake. Thank you, very much.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups