Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:11:35+00:00 2026-06-05T17:11:35+00:00

I have been searching for a solution to this and so far found nothing

  • 0

I have been searching for a solution to this and so far found nothing that works despite some others having similar issues. I am running an SQL statement using the following code (sorry about the hideous formatting. That is what we use here):

    /// <summary>
    /// Executes a prepared statement with the parameters passed to AddParameter(parameterName, parameterValue) and creates a recordset.
    /// </summary>
    /// 
    /// <param name="sqlQuery">The sql statement to execute.</param>
    public DbStandardResponseType ExecutePreparedStatementWithParametersQuery (string sqlQuery)
        {
        DbStandardResponseType dbFactoryResponse = new DbStandardResponseType();

        if (String.IsNullOrEmpty (sqlQuery))
            {
            dbFactoryResponse.ExceptionMessage = "No query string passed.";
            dbFactoryResponse.Success = false;
            dbFactoryResponse.UserFriendlyMessage = "No query string passed.";

            return dbFactoryResponse;
            }

        try
            {
            //attempt to prepare our connection
            dbFactoryResponse = PrepareConnection();

            if (!dbFactoryResponse.Success)
                {
                return dbFactoryResponse;
                }

            m_dbFactoryDatabaseCommand.CommandText = sqlQuery;
            m_dbFactoryDatabaseCommand.CommandType = CommandType.Text;

            if (m_parameterName.Count != 0)
                {
                for (int i = 0; i < m_parameterName.Count; i++)
                    {
                    //create a new parameter object and assign its values before adding it to the connection object
                    DbParameter parameter = m_dbFactoryDatabaseCommand.CreateParameter();
                    parameter.Value = m_parameterValue[i];
                    parameter.ParameterName = m_parameterName[i];
                    m_dbFactoryDatabaseCommand.Parameters.Add (parameter);
                    }

                m_parameterName.Clear();
                m_parameterValue.Clear();
                }

            m_hasRecordSet = true;

            *****Error appears on this line inside the reader object*****

            m_dbFactoryDatabaseDataReader = m_dbFactoryDatabaseCommand.ExecuteReader();

            dbFactoryResponse.ExceptionMessage = "";
            dbFactoryResponse.Success = true;
            dbFactoryResponse.UserFriendlyMessage = "OK";

            return dbFactoryResponse;
            }
        catch (Exception ex)
            {
            if (m_queueErrors)
                {
                m_queuedErrorsList.AppendLine (ex.Message);
                m_queuedErrorsList.AppendLine ("\r\n\r\nPrepared Statement: " + sqlQuery);
                m_queuedErrorsList.AppendLine();

                m_queuedErrorCount++;

                dbFactoryResponse.ExceptionMessage = m_queuedErrorsList.ToString();
                dbFactoryResponse.Success = false;
                dbFactoryResponse.UserFriendlyMessage = "Execute failed on the database.";
                }
            else
                {
                dbFactoryResponse.ExceptionMessage = ex.Message;
                dbFactoryResponse.Success = false;
                dbFactoryResponse.UserFriendlyMessage = "Execute failed on the database.";
                }

            try
                {
                Close();
                }
            catch (Exception f)
                {
                dbFactoryResponse.ExceptionMessage = f.Message + "\r\n\r\nPrepared Statement: " + sqlQuery;
                dbFactoryResponse.Success = false;
                dbFactoryResponse.UserFriendlyMessage = "Failed to close the connection to the database.";
                }

            return dbFactoryResponse;
            }
        }

The query is as follows (with values substituted in):

select CONTRIBUTO, count(*) as CountCol 
from HA_WITHOUT_SCOTLAND 
where 
GEOMETRY.STIntersects(geometry::STGeomFromText('POLYGON((-25.43623984375 44.257784519021, 21.62918984375 44.257784519021, 21.62918984375 60.752403080295, -25.43623984375 60.752403080295, -25.43623984375 44.257784519021))', 4326)) = 1 
group by CONTRIBUTO

CONRIBUTO column is a varchar(max)
GEOMETRY column is a geometry data type

When I run the statement directly on the database it runs without error and returns what I expect.

When I run it via the C# however using a prepared statement (obtained from a table earlier in the C# code) the error is produced. The parameters that are passed in are as follows:

@5 = -25.43623984375 double
@6 = 44.257784519021 double
@7 = 21.62918984375  double
@8 = 60.752403080295 double

The query without substituted values is as follows:

select CONTRIBUTO, count(*) 
from HA_WITHOUT_SCOTLAND
where STIntersects(GEOMETRY, geometry::STGeomFromText('POLYGON(('+@5+' '+@6+', '+@7+' '+@6+', '+@7+' '+@8+', '+@5+' '+@8+', '+@5+' '+@6+'))', 4326)) = 1 
group by CONTRIBUTO

I cannot see anywhere in here that would produce this error given the fact that the columns and parameters are the correct data types.

Can anyone shed any light on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:11:37+00:00Added an answer on June 5, 2026 at 5:11 pm

    The problem is down to the section that reads:

    'POLYGON(('+@5+'...
    

    This will attempt to convert the text POLYGON((' into a float so that it matches the @S parameter (so they can be added).

    Instead, you could try wrapping each parameter in a CONVERT, for example:

    'POLYGON(('+CONVERT(VARCHAR(100),@5)+'...
    

    The everything will be a string for the + operator, which will concatenate them instead.

    In your substituted version, you’ve already handled the conversion to a varchar yourself, so there’s no problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching for this solution for some time have not found any
I have been searching for a solution to my problem but haven't found anything
I have been searching for a solution to this for a while and have
I have been searching for a solution for this issue for multiple hours today
I have been searching everywhere but can't seem to find a solution to this
So I have been searching everywhere for a solution to this problem. I have
I have been searching all weekend for the solution to this quandry and have
Hi I have been searching a solution to this problem for many days but
So I have been searching for a solution for this a while now, and
I've been searching for a solution to this problem endlessly and thus far, haven't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.