MYSQL secure-file-priv is set to blank, but when running DbDataReader ExecuteReader it behaves as if it is not
P粉794851975
P粉794851975 2023-09-02 09:46:46
0
1
528
<p>I have set secure-file-priv="" in my.ini file If I run the SQL block in MySQL WorkBench, it runs perfectly. </p> <p>However, when C# actually runs the DbDataReader ExecuteReader, I get an error. <strong>The error tells me that the file doesn't exist, but that's because it appends the default path ("'C:\ProgramData\MySQL\MySQL Server 8.0\Data") to the beginning of the path< /strong> (The command text is exactly the same as the SQL below)</p> <p>Valid string examples</p> <pre class="brush:php;toolbar:false;">LOAD DATA INFILE '_FILEPATH.txt_' INTO TABLE tablename FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' IGNORE 1 LINES (xxx, yyy, zzz)</pre> <p>Error returned after executing Reader, now with added section</p> <blockquote> <p>MySqlException: File '<strong>C:\ProgramData\MySQL\MySQL Server 8.0\Data\DBNAME</strong>_FILEPATH.txt_' not found (OS Error 2 - No such file or directory)</p> </blockquote> <p>I don’t want it to contain<strong>“C:\ProgramData\MySQL\MySQL Server 8.0\Data\DBNAME"</strong>, I don't understand why this is happening. Any help would be greatly appreciated!</p>
P粉794851975
P粉794851975

reply all(1)
P粉384244473

This is not the answer to my question why it does weird things. However, I solved my problem using a different approach (by executing a Load-Infile).

I chose to use the MySQL client - MySQL Bulk Loader instead of using dbdatareader

string connectionString = Context.Database?.GetDbConnection().ToString();
        connectionString = "MY_CON_STRING"


        using (MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(connectionString))
        {
            connection.Open();
            MySql.Data.MySqlClient.MySqlBulkLoader loader = new MySql.Data.MySqlClient.MySqlBulkLoader(connection);
            loader.TableName = "TABLENAME";
            loader.FieldTerminator = "\t";
            loader.LineTerminator = "\r\n";
            loader.NumberOfLinesToSkip = 1;
          
            // skip header row 
            loader.FileName = filePath;
            int rowsInserted = loader.Load();
            connection.Close();
        }

So, while I still want to know the answer to my question, this worked for me.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template