Database 将图像保存为varbinary,arraylength(第2部分)

Database 将图像保存为varbinary,arraylength(第2部分),database,silverlight,linq,image,varbinary,Database,Silverlight,Linq,Image,Varbinary,这是我的问题的一个后续问题,我的问题已经解决了(谢谢你),但现在我陷入了另一个错误 我试图在我的数据库中保存一个图像(称为“Afbeelding”),为此我制作了一个表,其中包括: id:int 来源:varbinary(最大值) 然后,我创建了一个wcf服务,将“Afbeelding”保存到数据库中 private static DataClassesDataContext dc = new DataClassesDataContext(); [OperationCont

这是我的问题的一个后续问题,我的问题已经解决了(谢谢你),但现在我陷入了另一个错误

我试图在我的数据库中保存一个图像(称为“Afbeelding”),为此我制作了一个表,其中包括:

  • id:int
  • 来源:varbinary(最大值)
然后,我创建了一个wcf服务,将“Afbeelding”保存到数据库中

    private static DataClassesDataContext dc = new DataClassesDataContext();

    [OperationContract]
    public void setAfbeelding(Afbeelding a)
    {
        //Afbeelding a = new Afbeelding();
        //a.id = 1;
        //a.source = new Binary(bytes);

        dc.Afbeeldings.InsertOnSubmit(a);
        dc.SubmitChanges();
    }
然后我在我的项目中放置一个对服务的引用,当我按下按钮时,我尝试将其保存到数据库中

    private void btnUpload_Click(object sender, RoutedEventArgs e)
    {

        Afbeelding a = new Afbeelding();

        OpenFileDialog openFileDialog = new OpenFileDialog();

        openFileDialog.Filter = "JPEG files|*.jpg";

        if (openFileDialog.ShowDialog() == true)
        {
                //string imagePath = openFileDialog.File.Name;
                //FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
                //byte[] buffer = new byte[fileStream.Length];
                //fileStream.Read(buffer, 0, (int)fileStream.Length);
                //fileStream.Close();

            Stream stream = (Stream)openFileDialog.File.OpenRead();
            Byte[] bytes = new Byte[stream.Length];
            stream.Read(bytes, 0, (int)stream.Length);
            string fileName = openFileDialog.File.Name;


            a.id = 1;
            a.source = new Binary { Bytes = bytes };

        }


        EditAfbeeldingServiceClient client = new EditAfbeeldingServiceClient();

        client.setAfbeeldingCompleted +=new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_setAfbeeldingCompleted);
        client.setAfbeeldingAsync(a);
    }

    void client_setAfbeeldingCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
        if (e.Error != null)
            txtEmail.Text = e.Error.ToString();
        else
            MessageBox.Show("WIN");
    }
我不确定是什么原因造成的,但我认为这与我将图像写入数据库的方式有关?(数组长度太大了,不知道怎么改)

谢谢你的帮助,
Thomas

看起来您需要更改绑定中的默认读卡器配额,将长度设置为适合您的值:

 <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880"/>


很可能重复,谢谢,当我将此添加到绑定时,会出现以下错误:“绑定具有无效的子readerQuotas”。当我把它放在一个类似于另一个问题的文件中时,我就不能再访问我的数据库了。(错误:)我解决了它,我必须把它放在二进制绑定中。谢谢
 <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880"/>