none
OdbcConnection.GetSchema vs SQLGetInfo

    Question

  • I have some legacy ODBC connection coding which uses the SQLGetInfo function to gather various connection details when requested. The code is currently being re-factored to .NET, however it still has to maintain a small amount backward compatibility until the remaining areas are also re-factored into .NET

    I need to be able to reproduce the follow c++ code using c# OdbcConnection.GetSchema()

    char strInstanceName[200];
    SQLSMALLINT lengthReturned;
    SQLGetInfo(myhInstance, SQL_SERVER_NAME, strInstanceName, 200, &lengthReturned);
    
    char strDSN[200];
    SQLSMALLINT lengthReturned;
    SQLGetInfo(myhInstance, SQL_DATA_SOURCE_NAME, strDSN, 200, &lengthReturned);
    
    char strActiveStmts[200];
    SQLSMALLINT lengthReturned;
    SQLGetInfo(myhInstance, SQL_ACTIVE_STATEMENTS, strActiveStmts, 200, &lengthReturned);
    
    char strActiveConns[200];
    SQLSMALLINT lengthReturned;
    SQLGetInfo(myhInstance, SQL_ACTIVE_CONNECTIONS, strActiveConns, 200, &lengthReturned);

    I've spent hours looking over the documentation and searching the web, but I'm unable to find or understand what the equivalent is using OdbcConnection.GetSchema(), even though the documentation and web lead me to believe this is the function to get all this information.

    How to example code would be nice :)

    Regards Darren

    Monday, January 21, 2013 11:07 AM

Answers

All replies

  • Hi Darren,

    Welcome to the MSDN Forum.

    Such properties is already existed:

    SQL_SERVER_NAME: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection.database.aspx

    SQL_DATA_SOURCE_NAME: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection.datasource.aspx

    SQL_ACTIVE_STATEMENTS: Call your API, this information is not contained in a connection object.

    SQL_ACTIVE_CONNECTIONS: Call your API, this information is not contained in a connection object.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by DIGGIDY_RMS Wednesday, January 23, 2013 9:56 AM
    Tuesday, January 22, 2013 8:08 AM
  • Hi Mike,

    Thanks for you response, just a couple of issues with what you have suggested.

    The OdbcConnection.Database property will not correctly return the server name, its does in the case of MS SQLServer, however running an Oracle connection, it returns the TNS Service Name as configured in the ODBC datasource setup, not the physical server name.

    The documentation, suggests its getting the SQL_ATTR_CURRENT_CATALOG property rather than the SQL_SERVER_NAME property, that is the property I know returns the physical server name when running under an oracle connection.

    The OdbcConnection.DataSource property is good, I can use that, but for the active statements and connections info, which you say to call your API, are you referring to calling the ODBC API direct within c#??

    Is there some kind of wrapper class which exposes the API functions, our does it require the use of InteropServices and DllImport to expose them myself?

    Regards

    Darren

    Tuesday, January 22, 2013 12:23 PM
  • Hi Darren,

    >>are you referring to calling the ODBC API direct within c#?

    Yes, such as you have mentioned SQLGetInfo.

    >>our does it require the use of InteropServices and DllImport to expose them myself?

    Yes, that is my meaning.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by DIGGIDY_RMS Wednesday, January 23, 2013 9:55 AM
    Wednesday, January 23, 2013 4:51 AM
  • The question seems to ask how to get a schema name using SQLGetInfo.

    Can you share how this is done?

    Monday, May 12, 2014 4:42 PM