Skip to content

Commit 8debdef

Browse files
committed
Throw exception if CommandText is set while reading.
1 parent 1c246cb commit 8debdef

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ public override void Prepare()
8585
// this is not actually true because "Prepared statement handles are defined to work only with strings that contain a single statement" (http://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-queries.html).
8686
}
8787

88-
public override string CommandText { get; set; }
88+
public override string CommandText
89+
{
90+
get => m_commandText;
91+
set
92+
{
93+
if (m_connection?.HasActiveReader ?? false)
94+
throw new InvalidOperationException("Cannot set MySqlCommand.CommandText when there is an open DataReader for this command; it must be closed first.");
95+
m_commandText = value;
96+
}
97+
}
98+
8999
public new MySqlTransaction Transaction { get; set; }
90100

91101
public new MySqlConnection Connection
@@ -265,6 +275,7 @@ private bool IsValid(out Exception exception)
265275
static int s_commandId = 1;
266276

267277
MySqlConnection m_connection;
278+
string m_commandText;
268279
MySqlParameterCollection m_parameterCollection;
269280
int? m_commandTimeout;
270281
CommandType m_commandType;

0 commit comments

Comments
 (0)