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
  1. Home
  2. General Programming
  3. C#
  4. Schema and OdbcConnection

Schema and OdbcConnection

Scheduled Pinned Locked Moved C#
databasequestionxml
2 Posts 1 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.
  • P Offline
    P Offline
    PaleyX
    wrote on last edited by
    #1

    How do I get the database schema once I have set up an OdbcConnection? Primarily I need a list of tables and columns in the database. My App needs to be able to connect to any ODBC datasource and work out what tables and columns it contains. TIA

    P 1 Reply Last reply
    0
    • P PaleyX

      How do I get the database schema once I have set up an OdbcConnection? Primarily I need a list of tables and columns in the database. My App needs to be able to connect to any ODBC datasource and work out what tables and columns it contains. TIA

      P Offline
      P Offline
      PaleyX
      wrote on last edited by
      #2

      I have started to use the ODBC calls and P/Invoke as the Odbc stuff is .Net is sorely lacking. Still can't get it work though. IntPtr henv; short ret; // Allocate environment handle ret = SQLAllocHandle(SQL_HANDLE_ENV, (IntPtr)SQL_NULL_HANDLE, out henv); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { ret = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,(IntPtr)SQL_OV_ODBC3, 0); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { IntPtr hdbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, henv, out hdbc); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { // ret = SQLConnect(hdbc, dsn, SQL_NTS, null, SQL_NTS, null, SQL_NTS); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { IntPtr hstmt; ret = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, out hstmt); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { ret = SQLTables(hstmt, null, SQL_NTS, null, SQL_NTS, null, SQL_NTS, null, SQL_NTS); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { StringBuilder tableName = new StringBuilder(256); int tableNameLen; ret = SQLBindCol(hstmt, 2, 1, tableName, 256, out tableNameLen); if(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { while(SQLFetch(hstmt) == SQL_SUCCESS) { Console.WriteLine(tableName + ":" + tableNameLen.ToString()); } } } ret = SQLFreeHandle(SQL_HANDLE_STMT, hstmt); } ret = SQLDisconnect(hdbc); } // ret = SQLFreeHandle(SQL_HANDLE_DBC, hdbc); } } ret = SQLFreeHandle(SQL_HANDLE_ENV, henv); } The SQLFetch will be called as many times as there are tables in the dsn but the dsn is empty and tableNameLen is -1. Rugby League: The Greatest Game Of All.

      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