“GET_FILESTREAM_TRANSACTION_CONTEXT”的错误 [英] error for "GET_FILESTREAM_TRANSACTION_CONTEXT"
本文介绍了“GET_FILESTREAM_TRANSACTION_CONTEXT”的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想在sql server db中存储和检索文件
可能是商店代码。但是检索代码将面临这个错误:
'GET_FILESTREAM_TRANSACTION_CONTEXT'不是公认的内置函数名称
检索代码:
Hi
i wants to store and retrieve file in sql server db
the code of store work probably. but code of retrieve would be faced to this error:
'GET_FILESTREAM_TRANSACTION_CONTEXT' is not a recognized built-in function name"
code of retrieve :
private void btnOpen_Click(object sender, EventArgs e)
{
string cs = @"Data Source=<your server="">;Initial Catalog=MyFsDb;Integrated Security=TRUE";
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlTransaction txn = con.BeginTransaction();
string sql = "SELECT fData.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT(), fName FROM MyFsTable";
SqlCommand cmd = new SqlCommand(sql, con, txn);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string filePath = rdr[0].ToString();
byte[] objContext = (byte[])rdr[1];
string fName = rdr[2].ToString();
SqlFileStream sfs = new SqlFileStream(filePath, objContext, System.IO.FileAccess.Read);
byte[] buffer = new byte[(int)sfs.Length];
sfs.Read(buffer, 0, buffer.Length);
sfs.Close();
// Just write all files in the table to the temp direcotory.
// This is probably not how you would do it in the real world. But this is just an example.
string filename = @"C:\Temp\" + fName;
System.IO.FileStream fs = new System.IO.FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
rdr.Close();
txn.Commit();
con.Close();
}
}
推荐答案
尝试:
string sql =
"SELECT fData.PathName(), dbo.GET_FILESTREAM_TRANSACTION_CONTEXT(), fName FROM MyFsTable";
/ ravi
这篇关于“GET_FILESTREAM_TRANSACTION_CONTEXT”的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文