Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have enabled FileStream and created this table on sql server:
CREATE TABLE dbo.PictureTable
PkId int Primary Key IDENTITY (1, 1),
Id uniqueidentifier NOT NULL Unique ROWGUIDCOL Default newid(),
Description nvarchar(64) NOT NULL,
FileSummary varbinary(MAX),
FileData varbinary(MAX) FileStream NULL

and use this code snippet for inserting rows :
private void btnInsert_Click(object sender, EventArgs e)
    using (TransactionScope transactionScope = new TransactionScope())
        SqlConnection sqlConnection1 = new SqlConnection(@"Data Source=REZA-PC;Initial Catalog=FileStreamTest;Integrated Security=True");
        SqlCommand sqlCommand1 = sqlConnection1.CreateCommand();
        sqlCommand1.CommandText = @"Insert Into PictureTable (Description ,FileData ) Values(cast( NEWID() as nvarchar(64)),Cast('' as varbinary(max))) ";




no error
but the code do not insert any row to database where as the identity of PkId filed changes every time i click btnInsert!
i can use same query in sql server managment studio and it inserts rows without any problem
Insert Into PictureTable (Description ,FileData ) Values(cast( NEWID() as nvarchar(64)),
Cast('' as varbinary(max))) 
[no name] 12-Sep-13 15:57pm    
Mostly because you are never committing the transaction.
Rob Philpott 12-Sep-13 17:28pm    
Duh - done it again, comment in wrong place. "Yes! That should be an answer, not a comment!"
Reza Oruji 13-Sep-13 1:32am    
yes it's true. i append transactionScope.complete() to end of code and it works.thank you
Rob Philpott 12-Sep-13 17:28pm    
Yes! That should be an answer, not a comment!
sp_suresh 13-Sep-13 0:37am    
How to enable FileStream in SQL server pl tell me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900