2.
Then if you have account go to the dashboard
4.
Choose About URLs from left panel and click
6. Choose radio button Buy a custom domain through
Blogger.
This is a open code forum with some good code which makes you help to solve your coding problem.
FileStream
data type.EXEC sp_configure filestream_access_level, 2
GO
RECONFIGURE
GO
The filestream_access_level 2
means that it is available
for both SQL Server and from a client application.FileStream
, add a new file group with Name FileStream
and enable default.FileSystemDB_FileStream
. FileType
as FileStream
data. FileGroup
as FileStream
which was created in step 4. Path
. 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
)
The important points for this are as follows. The Table
has a column Id which is of type uniqueidentifier
(Guid
) and is a RowGuid
column. This is important because the files will be stored using this name. FileData
which is of type VarBinary
and FileStream
. This will be used to stream data.Insert Into PictureTable([Description],[FileData])
Values('Hello World', Cast('Hello World' As varbinary(max)))
And then select using the statement
SELECT [PkId],[Id],[Description],[FileData],CAST([FileData] _
As varchar(Max)) FROM [PictureTable]
guid
name each representing the rows stored. This is the Guid
with the same value as the row guid column created in the table above. HelloWorld
is a part of this file. insert
and Update
form parts of file writing. Delete can be done using regular SQL statements used for deleting rows. SqlFileStream
,
it has to be done in a transition. This is because in regular SQL
statements, data is returned back in an atomic manner however with SqlFileStream
data type the data is streamed from server to client using a buffer and hence there is no atomic operation. SqlFileStream
data type works with Integrated authentication only. using (TransactionScope transactionScope = new TransactionScope())
{
SqlConnection sqlConnection1 = new SqlConnection("Data Source=.;
Initial Catalog=FileSystemDB;Integrated Security=True");
SqlCommand sqlCommand1 = sqlConnection1.CreateCommand();
sqlCommand1.CommandText = "Insert Into PictureTable
(Description,FileData) values('" + Guid.NewGuid().ToString() +
"',Cast('' As varbinary(Max))); Select FileData.PathName()
As Path From PictureTable Where PkId =@@Identity";
sqlConnection1.Open();
string filePath1 = (string)sqlCommand1.ExecuteScalar();
SqlConnection sqlConnection2 = new SqlConnection("Data Source=.;
Initial Catalog=FileSystemDB;Integrated Security=True");
SqlCommand sqlCommand2 = sqlConnection2.CreateCommand();
sqlCommand2.CommandText = "Select GET_FILESTREAM_TRANSACTION_CONTEXT()
As TransactionContext";
sqlConnection2.Open();
byte[] transactionContext1 =(byte[]) sqlCommand2.ExecuteScalar();
SqlFileStream sqlFileStream1 = new SqlFileStream
(filePath1, transactionContext1, FileAccess.Write);
byte[] fileData = Guid.NewGuid().ToByteArray();
sqlFileStream1.Write(fileData, 0, fileData.Length);
sqlFileStream1.Close();
transactionScope.Complete();
}
The first statement is using (TransactionScope transactionScope = new TransactionScope()
) which starts a transaction scope. Insert Into PictureTable (Description ,FileData ) Values(“Some String made using Guid”,
Cast(‘’ as varchar(max))
What we do here is that we create an empty file. This is done because we need the file path to upload the file. Select FileData.Pathname() As Path From PictureTable where PkId = @@Identity
This returns us the location of file path as a UNC share. Select GET_FILESTREAM_TRANSACTION_CONTEXT()
this
returns back a transaction context which corresponds to the transaction
scope. It is in this transaction context that the file will be read. SqlFileStream
is opened using the file path and transaction context. The code after this is a simple upload of byte array to a file stream. SqlFileStream
is opened using this context and byte[]
is read from the same. The code given below shows the same:using (TransactionScope transactionScope2 = new TransactionScope())
{
SqlConnection sqlConnection3 = new SqlConnection("Data Source=.;
Initial Catalog=FileSystemDB;Integrated Security=True");
SqlCommand sqlCommand3 = sqlConnection3.CreateCommand();
sqlCommand3.CommandText = "Select FileData.PathName() As Path,
GET_FILESTREAM_TRANSACTION_CONTEXT() As TransactionContext
From PictureTable Where PkId = (Select Max(PkId) From PictureTable)";
sqlConnection3.Open();
SqlDataReader reader = sqlCommand3.ExecuteReader();
reader.Read();
string filePath = (string)reader["Path"];
byte[] transactionContext2 = (byte[])reader["TransactionContext"];
SqlFileStream sqlFileStream2 = new SqlFileStream
(filePath, transactionContext2, FileAccess.Read);
byte[] data = new byte[sqlFileStream2.Length];
sqlFileStream2.Read(data, 0, Convert.ToInt16(sqlFileStream2.Length));
Guid valueInserted = new Guid(data);
sqlFileStream2.Close();
}