Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-927403: Bind variable not set error - passing array to snowflake SQL SP #780

Closed
cse-manish opened this issue Sep 29, 2023 · 5 comments
Assignees
Labels
question Issue is a usage/other question rather than a bug

Comments

@cse-manish
Copy link

"Bind variable not set" error coming when passing array type parameter to snowflake SQL SP. Please see attached screenshot.

Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!

  1. What version of .NET driver are you using?
    =>4.7.2 dot net framework, using latest version of snowflake connector

  2. What operating system and processor architecture are you using?
    =>Windows

  3. What version of .NET framework are you using?
    E.g. .net framework 4.5.2 or .net standard 2.0
    => 4.7.2 dot net framework

  4. What did you do?
    => I am trying to call a snowflake SQL SP that takes array input parameter from dot net code. The program is giving "bind variable :p_id not set" error.
    Please see attached screenshot.
    P_id is my array type input param in the SP.
    Sorry for pasting screenshot instead of actual code text, github website is blocked on my office intranet.

  5. What did you expect to see?
    => expecting the DB CALL to go successfully instead of seeing an error

  6. Can you set logging to DEBUG and collect the logs?

    https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors

    There is an example in READMD.md file showing you how to enable logging.

  7. What is your Snowflake account identifier, if any? (Optional)

1695964615660784548994147735817

@cse-manish cse-manish added the bug label Sep 29, 2023
@github-actions github-actions bot changed the title Bind variable not set error - passing array to snowflake SQL SP SNOW-927403: Bind variable not set error - passing array to snowflake SQL SP Sep 29, 2023
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Oct 1, 2023
@sfc-gh-dszmolka sfc-gh-dszmolka added question Issue is a usage/other question rather than a bug status-triage Issue is under initial triage and removed bug labels Oct 1, 2023
@sfc-gh-dszmolka
Copy link
Contributor

hi and thank you for submitting this issue! i'm probably missing something, but is there a specific reason you're using ExecuteScalar ?
Perhaps it's worth a try using the example from the documentation and

  • calling ExecuteNonQuery instead of ExecuteScalar
  • even though I think a named variable should work (:P_ID) but how about trying ? instead, does it. make a difference ?

@sfc-gh-dszmolka sfc-gh-dszmolka added the status-information_needed Additional information is required from the reporter label Oct 1, 2023
@cse-manish
Copy link
Author

cse-manish commented Oct 2, 2023 via email

@sfc-gh-dszmolka
Copy link
Contributor

sfc-gh-dszmolka commented Oct 3, 2023

tested this and got to the same error as you do. when feeding the arguments to the SP as an array binding, it fails with Bind variable :P_ID not set. .
interestingly, if I feed the same array of input in a 'hardcoded' way (CALL test_db.public.test([1011,1012]);) instead of array binding, it works. so at this point I'm not sure if this is an expected behaviour - we're going to take a look and I'll keep this ticket posted with the investigation results.

edit: one of my colleagues came along and enlightened me; we never supported binding an array and it is indeed not supported today. How people apparently do this today, is to pass local arrays as SQL arrays via bind is to use the SQL form CALL SP(PARSE_JSON(?)) and then pass a JSON encoded array as string to ?

Here's a very simple example which works for me; and also binds an array of values as a variable. Hope it helps you too:

using System;
using System.Data;
using System.Data.Common;
using Snowflake.Data.Client;
using Newtonsoft.Json;
namespace SnowflakeTestProgram
{
    class Program
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        static void Main(string[] args)
        {
            try
            {
                using (IDbConnection conn = new SnowflakeDbConnection())
                {
                    conn.ConnectionString = "account=myaccount.eu-central-1; user=admin; password=mypassword; DB=TEST_DB; SCHEMA=PUBLIC; warehouse=COMPUTE_WH";
                    conn.Open();
                    Console.WriteLine("Connection successful!");
                    using (IDbCommand cmd = conn.CreateCommand())
                    {

                        int[] vals = new int[] { 1, 2, 3 };
                        string array = JsonConvert.SerializeObject(vals); // This class is from Newtonsoft json, also a driver dependency,
                        string sql = "CALL test_db.public.test(parse_json(?))";
                        // execute this sql with bind variable 'array'
                        cmd.CommandText = sql;

                        var p1 = cmd.CreateParameter();
                        p1.ParameterName = "1";
                        p1.Value = array;
                        p1.DbType = DbType.String;
                        cmd.Parameters.Add(p1);

                        IDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            Console.WriteLine(reader.GetString(0));
                        }
                        conn.Close();
                    }
                }
            }
            catch (DbException exc)
            {
                Console.WriteLine("Error Message: {0}", exc.Message);
            }
        }
    }
}

@sfc-gh-dszmolka sfc-gh-dszmolka added bug status-in_progress Issue is worked on by the driver team and removed question Issue is a usage/other question rather than a bug status-triage Issue is under initial triage status-information_needed Additional information is required from the reporter labels Oct 3, 2023
@sfc-gh-dszmolka sfc-gh-dszmolka added question Issue is a usage/other question rather than a bug and removed bug status-in_progress Issue is worked on by the driver team labels Oct 3, 2023
@sfc-gh-dszmolka
Copy link
Contributor

no update on this for a while so marking it as closed - if you still think you hit a bug in the Snowflake .NET driver, please comment with the details and we can look into it further.

@sfc-gh-dszmolka sfc-gh-dszmolka closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
@powerpoint123
Copy link

this is still an issue, can it be addressed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issue is a usage/other question rather than a bug
Projects
None yet
Development

No branches or pull requests

4 participants