The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)

Roman Gelfand 21 Reputation points
2022-07-22T02:57:38.257+00:00

In c# applicaction, the following code

		SqlXmlCommand cmd = new SqlXmlCommand("Provider=SQLOLEDB;" + connectionString);  
		cmd.CommandType = SqlXmlCommandType.Sql;  
		string commandText = "exec " + procName + " ";  

                   	foreach (SqlParameter param in commandParameters)  
		{  
			if (adComma) commandText += ", ";  

			string paramValue = Convert.ToString(param.Value);  
			if ((param.SqlDbType == SqlDbType.NVarChar || param.SqlDbType == SqlDbType.NText)   
				&& paramValue.IndexOf("'") != -1)	  
				paramValue = paramValue.Replace("'", "''");  

			if (param.SqlDbType == SqlDbType.NVarChar ||  
				param.SqlDbType == SqlDbType.NText)  
			{  
				commandText += "N'" + paramValue + "'";  
			}  
			else if (param.SqlDbType == SqlDbType.UniqueIdentifier ||   
				param.SqlDbType == SqlDbType.SmallDateTime ||  
				param.SqlDbType == SqlDbType.DateTime)  
				commandText += "'" + paramValue  + "'";  
			else  
				commandText += paramValue;  
			adComma = true;  
		}  
		Stream o = null;  
		cmd.CommandText = commandText;  

            When it runs this command, it fails with        The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)  

                  o = cmd.ExecuteStream();  

The db engine is sql server 2014 sp3. I ran the contents of commandText on ssms and got legitimate result. What does this error mean and how to fix it?

Thanks in advance

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,756 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,276 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,554 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Olaf Helper 40,901 Reputation points
    2022-07-22T09:26:32.623+00:00

    SqlXmlCommand cmd = new SqlXmlCommand ...

    Why SqlXmdCommand? Don't make sense in your scenario. Use SqlCommand instead
    https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-6.0

    And don't create dynamically SQL statement, that opens doors for SQL injection and really like to fail at all.

    0 comments No comments