How to retrieve Oracle long type data using the ODP.NET driver in Visual Studio?

zhihao huang 20 Reputation points
2025-12-12T02:28:15.2+00:00

I'm developing a Visual Studio plugin that uses the database connection provided by Visual Studio to retrieve Oracle metadata. However, when the metadata is of type Long (ALL_TAB_COLS.DATA_DEFAULT), the data cannot be retrieved in Visual Studio (it's an empty string).

I tried:

  1. After consulting resources, I was able to set InitialLONGFetchSize = -1 to load Oracle Long type data.
  2. I used the IVsDataConection (from IVsDataExplorerConnectionManager) object for database connection, but I couldn't find a way to pass the InitialLONGFetchSize property.
Developer technologies | Visual Studio | Extensions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-12T02:28:25.1+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To retrieve Oracle LONG type data using the ODP.NET driver in Visual Studio, you can follow these steps:

    1. Set InitialLONGFetchSize: You already mentioned setting InitialLONGFetchSize = -1. This is a correct approach as it allows the driver to fetch the entire LONG data when retrieving it.
    2. Using the ODP.NET Driver: Ensure that you are using the ODP.NET driver correctly to access the LONG data. If you are using OracleDataReader, you can retrieve LONG data by calling GetOracleString or GetOracleBinary methods, depending on the type of LONG data you are dealing with.
    3. Connection Configuration: Since you are using IVsDataConnection, you may need to check if there is a way to configure the connection string or properties to include the InitialLONGFetchSize. This might not be directly exposed through IVsDataConnection, so you may need to look into the underlying connection string or configuration options available in ODP.NET.
    4. Testing with a Simple Query: As a test, run a simple query that selects the LONG column directly to see if it returns data. This can help isolate whether the issue lies with the connection setup or the way the data is being fetched.

    If you continue to face issues, consider checking the Oracle documentation for any specific configurations or limitations regarding LONG data types and ODP.NET.


    References:

    0 comments No comments

  2. Varsha Dundigalla(INFOSYS LIMITED) 3,885 Reputation points Microsoft External Staff
    2025-12-12T09:37:13.7933333+00:00

    Thank you for reaching out.

    Oracle LONG columns return empty strings because InitialLONGFetchSize defaults to 0, so no LONG data is fetched.

    Set InitialLONGFetchSize to -1 in your connection string and use ODP.NET reader methods.

    var csb = new OracleConnectionStringBuilder(vsConnStr)

    {

        InitialLONGFetchSize = -1

    };

    var conn = new OracleConnection(csb.ToString());

    conn.Open();

    var cmd = new OracleCommand("SELECT DATA_DEFAULT FROM ALL_TAB_COLS WHERE TABLE_NAME='YourTable'", conn);

    var reader = cmd.ExecuteReader();

    var longValue = reader.GetOracleString(0);

    This ensures the entire LONG value is retrieved.

    Please let us know if you require any further assistance, we’re happy to help.

    If you found this information useful, kindly mark this as "Accept Answer".

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.