error for "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();

    }

    }

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply