DBI/ODBC question: how to create DB programmatically?

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default DBI/ODBC question: how to create DB programmatically?

    Hi,

    I've been trying to figure out how to use ODBC with DBI. So far, I have
    created a DSN for an existing DB and managed to read tables, update them,
    etc, but I'd like to be able to create a new DB from scratch
    programmatically (i.e. without any manual steps to create a DSN and add a
    database).

    Is there a way to do this from the DBI interface? I've found a few VB
    examples and dug around in the ODBC source code, but I can't quite make the
    leap from the VB code to the DBI API.

    I'm using Windows XP and Ruby 1.8.0.

    Thanks,

    Dave Halliday



    Dave Halliday Guest

  2. Similar Questions and Discussions

    1. create ODBC connection in CF?
      Is there a way to create ODBC DSNs via code? Even if I have to execute something in another language...
    2. [HOW TO DO] Programmatically create photograms?
      LOT for you reply. Now I have the problem to refer to generated movieClip (how is it possible by name?) to move then and generate "trailer titles"...
    3. Programmatically create buttons from user control
      Hello guys, I have an application which is built upon several user controls. That is, I have a default template (default.aspx) that I load a user...
    4. create treeview control programmatically
      see http://support.microsoft.com/default.aspx?scid=KB;EN-US;210125 "William Grigg" <wgrigg@draper.com> wrote in message...
    5. Programmatically create HTTP post
      Thanks for the reply, Bob. Unfortunately this won't work for me. The external web site is expecting an HTTP POST document. My .asp server page...
  3. #2

    Default Re: DBI/ODBC question: how to create DB programmatically?

    On Thu, Sep 11, 2003 at 11:51:08AM +0900, Dave Halliday wrote:
    > Hi,
    >
    > I've been trying to figure out how to use ODBC with DBI. So far, I have
    > created a DSN for an existing DB and managed to read tables, update them,
    > etc, but I'd like to be able to create a new DB from scratch
    > programmatically (i.e. without any manual steps to create a DSN and add a
    > database).
    There's no special command to create databases with DBI/ODBC. Usually,
    you can create a database by issuing the "CREATE DATABASE ..." SQL
    statement, but this will probably not create a DSN for you.
    > Is there a way to do this from the DBI interface? I've found a few VB
    > examples and dug around in the ODBC source code, but I can't quite make the
    > leap from the VB code to the DBI API.
    Everything what you can do in VB should be possible in Ruby by using the
    win32ole module (this is how the ADO database driver is implemented).
    > I'm using Windows XP and Ruby 1.8.0.
    Have a look at the ADO database driver (part of DBI in directory
    lib/dbd_ado). Look how it's using the ADODB.Connection COM object, and
    try to translate the VB example into Ruby.

    Hope this helps.


    Regards,

    Michael

    Michael Neumann Guest

  4. #3

    Default Re: DBI/ODBC question: how to create DB programmatically?

    Dave Halliday wrote:
    >Hi,
    >
    >I've been trying to figure out how to use ODBC with DBI. So far, I have
    >created a DSN for an existing DB and managed to read tables, update them,
    >etc, but I'd like to be able to create a new DB from scratch
    >programmatically (i.e. without any manual steps to create a DSN and add a
    >database).
    >
    Access:

    cat = WIN32OLE.new('ADOX.Catalog')
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=#{@out_mdb_fn}"

    SQL Server:

    db = WIN32OLE.new("ADODB.Connection")
    db.Open "Provider=SQLOLEDB;Data Source=myserver;Database=master;..."
    db.execute("CREATE DATABASE mydb")

    --

    Chris
    [url]http://clabs.org/blogki[/url]



    Chris Morris Guest

  5. #4

    Default Re: DBI/ODBC question: how to create DB programmatically?

    Thanks Chris. That's what I was looking for. I never thought of using
    win32ole.

    In the meantime, I did manage to create an Access database using the
    undocumented add_dsn() method in the ODBC driver:

    drv = ODBC::Driver.new
    drv.name = "Microsoft Access Driver (*.mdb)"
    drv.attrs = {"CREATE_DB" => ".\\test.mdb General"}
    ODBC.add_dsn(drv)

    Cheers,

    Dave

    "Chris Morris" <chrismo@clabs.org> wrote in message
    news:3F60CFF0.8000805@clabs.org...
    > Dave Halliday wrote:
    >
    > >Hi,
    > >
    > >I've been trying to figure out how to use ODBC with DBI. So far, I have
    > >created a DSN for an existing DB and managed to read tables, update them,
    > >etc, but I'd like to be able to create a new DB from scratch
    > >programmatically (i.e. without any manual steps to create a DSN and add a
    > >database).
    > >
    > Access:
    >
    > cat = WIN32OLE.new('ADOX.Catalog')
    > cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=#{@out_mdb_fn}"
    >
    > SQL Server:
    >
    > db = WIN32OLE.new("ADODB.Connection")
    > db.Open "Provider=SQLOLEDB;Data Source=myserver;Database=master;..."
    > db.execute("CREATE DATABASE mydb")
    >
    > --
    >
    > Chris
    > [url]http://clabs.org/blogki[/url]
    >
    >
    >

    Dave Halliday Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139