• <legend id='fYtlz'><style id='fYtlz'><dir id='fYtlz'><q id='fYtlz'></q></dir></style></legend>

    1. <small id='fYtlz'></small><noframes id='fYtlz'>

      • <bdo id='fYtlz'></bdo><ul id='fYtlz'></ul>

      <i id='fYtlz'><tr id='fYtlz'><dt id='fYtlz'><q id='fYtlz'><span id='fYtlz'><b id='fYtlz'><form id='fYtlz'><ins id='fYtlz'></ins><ul id='fYtlz'></ul><sub id='fYtlz'></sub></form><legend id='fYtlz'></legend><bdo id='fYtlz'><pre id='fYtlz'><center id='fYtlz'></center></pre></bdo></b><th id='fYtlz'></th></span></q></dt></tr></i><div id='fYtlz'><tfoot id='fYtlz'></tfoot><dl id='fYtlz'><fieldset id='fYtlz'></fieldset></dl></div>

        <tfoot id='fYtlz'></tfoot>
      1. SQL:按顺序对 VarBinary 列执行 UPDATE .WRITE

        SQL: Sequentially doing UPDATE .WRITE on VarBinary column(SQL:按顺序对 VarBinary 列执行 UPDATE .WRITE)
        <tfoot id='T1cVf'></tfoot>
        <i id='T1cVf'><tr id='T1cVf'><dt id='T1cVf'><q id='T1cVf'><span id='T1cVf'><b id='T1cVf'><form id='T1cVf'><ins id='T1cVf'></ins><ul id='T1cVf'></ul><sub id='T1cVf'></sub></form><legend id='T1cVf'></legend><bdo id='T1cVf'><pre id='T1cVf'><center id='T1cVf'></center></pre></bdo></b><th id='T1cVf'></th></span></q></dt></tr></i><div id='T1cVf'><tfoot id='T1cVf'></tfoot><dl id='T1cVf'><fieldset id='T1cVf'></fieldset></dl></div>

                <bdo id='T1cVf'></bdo><ul id='T1cVf'></ul>
                  <tbody id='T1cVf'></tbody>

              • <legend id='T1cVf'><style id='T1cVf'><dir id='T1cVf'><q id='T1cVf'></q></dir></style></legend>

                <small id='T1cVf'></small><noframes id='T1cVf'>

                • 本文介绍了SQL:按顺序对 VarBinary 列执行 UPDATE .WRITE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个小测试应用程序,它读取 FileStream 的块并将其附加到 SQL Server 2005 Express 上的 VarBinary(max) 列.

                  I'm trying to create a little test application which reads chunks of a FileStream and appends it to a VarBinary(max) column on an SQL Server 2005 Express.

                  一切正常 - 该列已按预期填充,但我的机器似乎仍将所有内容缓冲到内存中,我就是不明白为什么.

                  Everything works - the column gets filled as it's supposed to, but my machine still seems to buffer everything into memory and I just can't see why.

                  我正在使用以下代码 (C#):

                  I'm using the following code (C#):

                  using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
                  {
                      connection.Open();
                  
                      string id = Guid.NewGuid().ToString();
                  
                      using (IDbCommand command = connection.CreateCommand())
                      {
                          command.CommandText = "INSERT INTO [BLOB] ([Id],[Data]) VALUES (@p1,0x0)";
                  
                          SqlParameter param = new SqlParameter("@p1", SqlDbType.VarChar);
                          param.Value = id;
                          command.Parameters.Add(param);
                  
                          command.ExecuteNonQuery();
                      }
                  
                      if (File.Exists(textBox1.Text))
                      {
                          using (IDbCommand command = connection.CreateCommand())
                          {
                              command.CommandText = "UPDATE [BLOB] SET [Data].WRITE(@data, @offset, @len) WHERE [Id]=@id";
                  
                              SqlParameter dataParam = new SqlParameter("@data", SqlDbType.VarBinary);
                              command.Parameters.Add(dataParam);
                  
                              SqlParameter offsetParam = new SqlParameter("@offset", SqlDbType.BigInt);
                              command.Parameters.Add(offsetParam);
                  
                              SqlParameter lengthParam = new SqlParameter("@len", SqlDbType.BigInt);
                              command.Parameters.Add(lengthParam);
                  
                              SqlParameter idParam = new SqlParameter("@id", SqlDbType.VarChar);
                              command.Parameters.Add(idParam);
                              idParam.Value = id;
                  
                              using (FileStream fs = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read))
                              {
                                  byte[] buffer = new byte[2090400]; //chunk sizes that are multiples of 8040 bytes.
                                  int read = 0;
                                  int offset = 0;
                  
                                  while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
                                  {
                                      dataParam.Value = buffer;
                                      offsetParam.Value = offset;
                                      lengthParam.Value = read;
                  
                                      command.ExecuteNonQuery();
                  
                                      offset += read;
                                  }
                              }
                          }
                      }
                  }
                  

                  谁能告诉我为什么它将文件缓冲到内存中?我正在使用的 byte[] 缓冲区大小只有将近 2 MB.

                  Can anybody tell me why it buffers the file into memory? The byte[] buffer I'm using is only almost 2 MB in size.

                  我可以为每个块创建一个新缓冲区,但这似乎也浪费了 CPU/内存...

                  I could create a new buffer for each chunk, but that seems like a waste of CPU/memory also...

                  推荐答案

                  它会缓冲它,因为当你将它保存到 varbinary 列时,它会成为 sql server 中 LOB 数据缓存的一部分.这就是它的工作原理.

                  it buffers it because when you save it into the varbinary column it becomes part of the LOB data cache in sql server. that's how it works.

                  或者你的意思是它在其他地方缓冲?

                  or do you mean it gets buffered somewhere else?

                  这篇关于SQL:按顺序对 VarBinary 列执行 UPDATE .WRITE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)
                  1. <legend id='A8hLA'><style id='A8hLA'><dir id='A8hLA'><q id='A8hLA'></q></dir></style></legend>
                    <tfoot id='A8hLA'></tfoot>

                    <i id='A8hLA'><tr id='A8hLA'><dt id='A8hLA'><q id='A8hLA'><span id='A8hLA'><b id='A8hLA'><form id='A8hLA'><ins id='A8hLA'></ins><ul id='A8hLA'></ul><sub id='A8hLA'></sub></form><legend id='A8hLA'></legend><bdo id='A8hLA'><pre id='A8hLA'><center id='A8hLA'></center></pre></bdo></b><th id='A8hLA'></th></span></q></dt></tr></i><div id='A8hLA'><tfoot id='A8hLA'></tfoot><dl id='A8hLA'><fieldset id='A8hLA'></fieldset></dl></div>

                      • <bdo id='A8hLA'></bdo><ul id='A8hLA'></ul>

                        • <small id='A8hLA'></small><noframes id='A8hLA'>

                              <tbody id='A8hLA'></tbody>