Why is OdbcCommand.ExecuteScalar () throwing an AccessViolationException?

I have a code block designed to output text descriptions from a database table and save them in a text file. It looks like this (C # .NET):

        OdbcCommand getItemsCommand = new OdbcCommand("SELECT ID FROM ITEMS", databaseConnection);
        OdbcDataReader getItemsReader = getItemsCommand.ExecuteReader();
        OdbcCommand getDescriptionCommand = new OdbcCommand("SELECT ITEMDESCRIPTION FROM ITEMS WHERE ID = ?", databaseConnection);
        getDescriptionCommand.Prepare();
        while (getItemsReader.Read())
        {
            long id = getItemsReader.GetInt64(0);
            String outputPath = "c:\\text\\" + id + ".txt";
            if (!File.Exists(outputPath))
            {
                getDescriptionCommand.Parameters.Clear();
                getDescriptionCommand.Parameters.AddWithValue("id", id);
                String description = (String)getDescriptionCommand.ExecuteScalar();
                StreamWriter outputWriter = new StreamWriter(outputPath);
                outputWriter.Write(description);
                outputWriter.Close();
            }
        }
        getItemsReader.Close();

This code successfully saved some of the data in TXT files, but for many lines, an AccessViolationException was thrown on the following line:

                String description = (String)getDescriptionCommand.ExecuteScalar();

Exceptional text: "Attempted to read or write protected memory. This often indicates damage to another memory."

The program, as a rule, throws an exception in the same rows of the table, but it does not correspond to 100%. Sometimes data that unexpectedly throws an exception is triggered unexpectedly.

, , , SELECT ID, ITEMDESCRIPTION FROM ITEMS getItemsCommand . , , getItemsCommand.GetString(). , , , , , . , , . . - , ?

, ID - INT, ITEMDESCRIPTION - VARCHAR (32000). , Borland Interbase 6.0 (Ick!)

EDIT: , !! ARGH!! . , , . , , , . , , 5 , . - , - ?

: . ​​ ODBC . .

+3
2

ODBC, . ? ?

+1

...

, (, ) , . , getItemsCommand , , , ...

+1

Source: https://habr.com/ru/post/1698614/


All Articles