Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c将字节[]插入Informix DB中的blob列#_C#_Asp.net_Image_Blob_Informix - Fatal编程技术网

C# 使用c将字节[]插入Informix DB中的blob列#

C# 使用c将字节[]插入Informix DB中的blob列#,c#,asp.net,image,blob,informix,C#,Asp.net,Image,Blob,Informix,就像这些链接一样 我也无法在我的informix数据库上只插入与byte[]相关的操作。我尝试了很多方法并浏览了IBM网站。但没有解释“如何使用byte[]使用c#插入blob列” “链接4”非常有用。但我面临着这个代码的问题 Error: The %0 enumeration value, %1, is invalid. At line: blob.Open(IfxSmartLOBOpenMode.ReadWrite); if i use cmd.Parameters.Add(new

就像这些链接一样

我也无法在我的informix数据库上只插入与byte[]相关的操作。我尝试了很多方法并浏览了IBM网站。但没有解释“如何使用byte[]使用c#插入blob列”

“链接4”非常有用。但我面临着这个代码的问题

Error: The %0 enumeration value, %1, is invalid.
At line: blob.Open(IfxSmartLOBOpenMode.ReadWrite);
if i use cmd.Parameters.Add(new IfxParameter()).Value = byteuploaded`;
这是我的代码片段

protected void uploadfile_Click(object sender, EventArgs e)
    {
        string extension;
        // checks if file exists
        if (!_imageUpload.HasFile)
        {
            _resultLbl.Text = "Please, Select a File!";
            return;
        }
        // checks file extension
        extension = System.IO.Path.GetExtension(_imageUpload.FileName).ToLower();
        if (!extension.Equals(".jpg") && !extension.Equals(".jpeg") && !extension.Equals(".png"))
        {
            _resultLbl.Text = "Only image files (.JPGs and .PNGs) are allowed.";
            return;
        }
        try
        {
            // =========   This is not working   ==============
            string sqlQuery = "insert into db95:TestBlobUpload (id ,fileblob) values('2', 'two');";
            // =========   This is working properly  ==============
            //string sqlQuery = "insert into db95:TestBlobUpload (id ,filetext) values('4',?);";
            string connString = "Database=db95;Host=172.16.XX.XX;Server=vsXXXX;Service=88;Protocol=onsoctcp;UID=ed;Password=ca94;";
            using (this.connection = new IfxConnection(connString))
            {
                this.connection.Open();
                using (this.cmd = new IfxCommand(sqlQuery, this.connection))
                {
                    // Start a local transaction
                    this.trans = this.connection.BeginTransaction(IsolationLevel.Unspecified);
                    // Assign transaction object for a pending local transaction
                    this.cmd.Transaction = trans;
                    try
                    {


                        IfxBlob byteuploaded = new IfxBlob(this.connection);
                        byteuploaded.Read(_imageUpload.FileBytes);

                        // =========   BOTH OF THESE are not working   ==============
                        //cmd.Parameters.Add(new IfxParameter()).Value = data;// System.Text.Encoding.UTF8.GetString(data);
                        cmd.Parameters.Add(new IfxParameter()).Value = byteuploaded;// _imageUpload.FileBytes;

                        int res = cmd.ExecuteNonQuery();

                        // commiting the transaction
                        this.cmd.Transaction.Commit();
                    }
                    catch
                    {
                        //this.cmd.Transaction.Rollback();
                    }
                }
                this.connection.Close();
            }
        }
        catch (Exception)
        {

        }
    }
我将此dll用作参考并使用IBM.Data.Informix

我无法将字节[]添加到blob列中。我可以执行的所有其他插入/更新/删除操作

有什么帮助吗

我甚至升级到了ibm_data_server_driver_package_win64_v10.1.exe和clientsdk.4.10.FC1DE.WIN.exe

但是我面临着dll兼容性的问题。无法加载“XX.XX.dll”异常

我甚至尝试使用

INSERT INTO db95@vsXXXX:testblobupload (fileblob) 
   VALUES (db95@vsXXXX:FILETOBLOB('C:\tmp\Untitled.png', 'client'));
并面临着错误

ERROR: Smart-large-object error.
Error Code: -9810.
Smart Large Objects: No sbspace number specified.
这不是你的c#应用程序。这是需要为大型智能对象设置的Informix环境。我认为它基本上指定了在服务器上使用的空间。我不知道其他任何内容。如果你返回isam错误代码,它将是

-12053智能大对象:未指定sbspace编号

找不到默认的sbspace,并且调用方未指定sbspace 使用

在中指定智能大对象空间名称 智能大对象函数调用或设置SBSPACENAME onconfig
文件参数设置为有效的智能大对象空间的名称。

我们可以使用
PUT in
子句在特定的sbspace中包含blob字段


如果我们使用
connection.GetIfxBlob()
在不指定表名和列名的情况下,blob字段将包含在onconfig
SBSPACENAME
中设置的默认sbspace中,如果未设置,则会出现错误
SQLERR-9810 ISAM ERR-12053

,我想保存Informix blob的最佳方法是使用此函数:

    string insertSql = string.Format("insert into \"{0}\" (sbfotoint,NmArqBlob) values (?,?);", this.table);

        using (var command = new IfxCommand(insertSql, this.connection))
        {
            this.connection.Open();
            SetRole();
            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.Add(new IfxParameter()).Value = CreateIfxBlob(entidade.SBlob);
            command.Parameters.Add(new IfxParameter()).Value = entidade.NomeArquivo;
            command.ExecuteNonQuery();
            this.connection.Close();
        }

private IfxBlob CreateIfxBlob(byte[] data)
    {
        IfxBlob blob = connection.GetIfxBlob(this.table, "sbfotoint");
        blob.Open(IfxSmartLOBOpenMode.ReadWrite);
        blob.Write(data);
        blob.Close();
        return blob;
    }

你成功了?我也有同样的问题