当前位置:首页 >探索 >使用SQL Server 2008的FILESTREAM特性管理文件 正文

使用SQL Server 2008的FILESTREAM特性管理文件

来源:益强资讯优选   作者:人工智能   时间:2025-11-05 03:34:55
使用SQL Server 2008的FILESTREAM特性管理文件
复制private void btnWriteFile_Click(object sender,使用 EventArgs e) { string connectionString = ConfigurationManager.ConnectionStrings ["fileStreamDB"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(); command.Connection = connection; //Get the PathName of the File from the database command.CommandText = "SELECT Picture.PathName(), " + "GET_FILESTREAM_TRANSACTION_CONTEXT() FROM Product " + "WHERE ProductID = 1"; SqlTransaction transaction = connection.BeginTransaction (IsolationLevel.ReadCommitted); command.Transaction = transaction; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string path = reader.GetString(0); SqlFileStream stream = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Write, FileOptions.SequentialScan, 0); string contents = txtInput.Text; stream.Write((System.Text.Encoding.ASCII.GetBytes(contents)), 0, contents.Length); stream.Close(); } } transaction.Commit(); } MessageBox.Show("File contents successfully written"); } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.

标签:

责任编辑:数据库