查询超过1190个字符时,Db2连接挂起

sqxo8psd  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(163)

我有一个dotnet核心容器应用程序(linux),它使用以下代码对db2(z/os)进行异步SELECT调用:

var result = new DataTable();
            var query = "SELECT * FROM DB.TABLE WITH UR;"
            using (var connection = new DB2Connection(_connection))
            {
                await connection.OpenAsync();
                using (var command = new DB2Command(query, connection))
                {
                    using (var myReader = await command.ExecuteReaderAsync()) // fails here when query > 1190 chars
                    {
                        result.Columns.AddRange(myReader.GetColumnSchema()
                            .Select(x => new DataColumn(x.ColumnName, x.DataType))
                            .ToArray());
                        result.BeginLoadData();
                        while (await myReader.ReadAsync())
                        {
                            var contents = new object[myReader.FieldCount];
                            myReader.GetValues(contents);
                            result.LoadDataRow(contents, false);
                        }
                        result.EndLoadData();
                    }
                }
            }

此代码适用于任何少于1190个字符的查询。当我将sql字符串增加到1191个字符或更多时,调用将挂起并超时,并显示以下错误:
异常(0x 80004005):错误[08001] [IBM] SQL 30081 N检测到一个通信错误。正在使用的通信协议:“TCP/IP”。正在使用的通信API:“SOCKETS”。检测到错误的位置:“170.2.8.84“。通信功能检测到错误:“recv”。协议特定错误代码:“110”、“"、“"。SQLSTATE=08001*
在本地运行Docker时不会出现此问题。我无法在有问题的主机上运行Windows容器,因此无法进行比较。
委托单位:


# db2level

DB21085I  This instance or install (instance name, where applicable: "*") uses
"64" bits and DB2 code release "SQL11055" with level identifier "0606010F".
Informational tokens are "DB2 v11.5.5.1", "s2103171200", "DYN2103171200AMD64",
and Fix Pack "1".
Product is installed at "/app/clidriver".

DBA无法看到超时查询的任何活动。根据此特定大小阈值,哪些因素可能会阻碍这些调用?

6qqygrtg

6qqygrtg1#

要测试db2 cli是否可以执行相同的SQL语句(即独立于C#和独立于.net core),您可以复制并修改下面的脚本,方法是从凭据json文件(或您收到连接字符串详细信息的任何地方)复制主机名、用户名、口令和端口号。
如果您的连接未使用SSL/TLS加密,请修改脚本以从数据库和下面的dsn定义中删除Security=SSL参数,并使用正确的非SSL端口号。
如果您的密码包含了任何被您的linux shell认为是特殊的字符,在脚本中指定下面的密码变量时,请用反斜杠\转义每个这样的特殊字符。否则,您将得到SQL 30082 N reason“24”。
修改此文件后,使用chmod +x组合键修改该文件,然后运行它。


# !/bin/bash

# 

# populate db2dsdriver.cfg for Db2-on-cloud lite and verify db2cli connects and runs SQL statements.

# 

# Prereq: (1) an IBM Db2 CLI driver is already installed and on the PATH for current userid.

# Prereq: (2) the version of the CLI driver matches the version of the Db2-lite instance (per the UI dashboard)

# Prereq: (3) after you modify this file, remember to `chmod +x` this file before running it.

# 

# This script works with clidriver , with the Db2 runtime client, with the Db2 data server client (fat client).

# Can re-run this script, overwrites current matching entries in db2dsdriver.cfg (if exists) else creates that file.

# 

# For IBM Db2-on-cloud (lite plan ,  kostenlos ).

# Configure the db2dsdriver.cfg file for use with db2cli tool to connect to Db2-on-cloud from command-line bash.

# 

# You must modify the variable-values below by copying username, password, port, hostname from your credentials json file.

# And remember to escape ( precede with \) any and all special-character in password, otherwise connect will fail.

# 

# Note 1: this expects the Db2-on-cloud hostname to have SSL/TLS encrypted-connections to BLUDB which is the default

# for all IBM Db2-on-cloud hostnames ending with pattern *appdomain.cloud

# 

# Note 2: at clidriver version 11.5.6.0 , db2cli tool can return exit-code 0 even on failure, doh!

# 

# Note 3: to get your username and password, host and port-number , download the credentials json file and view it to see them.

# Then copy their values into the appropriate variables below before making this script executable and run it.

# 

set -u

typeset which=/usr/bin/which
typeset db2cli=$( ${which} db2cli )
        [[ -z ${db2cli:=""} ]] && print "\nERROR: please either  dot in a db2profile to allow db2cli to be on the PATH\nor edit your PATH environment variable to put the clidriver/bin directory on the PATH" && exit 1

typeset dbname=bludb   # default database-name for Db2-on-cloud lite plan shared databases.
typeset hostname="change me"
typeset ssl_port_number=32733  # from credentials json
typeset password="change me"  # remember to escape \ any special characters here, copy from credentials json file.
typeset username="change me"  # copy from credentials json file.
typeset dbalias=bludb # you can use whatever alias-name you like, 8 bytes long max
typeset input_sql_tmpfile=/tmp/db2cli_inputsql.sql

${db2cli} writecfg add -database ${dbname} -host ${hostname} -port ${ssl_port_number} -parameter Security=SSL
rc=$?
(( rc > 0 )) && print "\nERROR: failed to write the database to the config file\n" && exit 1

${db2cli} writecfg add -dsn ${dbalias} -database ${dbname} -host ${hostname} -port ${ssl_port_number} -parameter Security=SSL
rc=$?
(( rc > 0 )) && print "\nERROR: failed to write the dsn to the config file\n" && exit 1

${db2cli} validate -dsn ${dbalias} -connect -user ${username} -passwd ${password}
rc=$?
(( rc > 0 )) && print "\nERROR: failed to connect to the dsn with supplied credentials\n" && exit 1

# Verify that the db2cli tool can run some SQL statements by putting them into a file and passing the file to db2cli

# create an inputfile containing SQL statements ( make a temp file for this purpose)

# note that the default statement delimiter for db2cli is crlf (or lf on linux) not semicolon as with db2clp.

echo "values current timestamp" > ${input_sql_tmpfile}
echo "values current server" >> ${input_sql_tmpfile}
echo "values current user" >> ${input_sql_tmpfile}

${db2cli} execsql -execute -dsn ${dbalias} -user ${username} -passwd ${password} -inputsql ${input_sql_tmpfile}

相关问题