Showing posts with label save. Show all posts
Showing posts with label save. Show all posts

Monday, March 26, 2012

retrive a file from a binary data field

hello dear friends

I am trying to save a binary file to database with the following code:

publicstaticvoid memorystreamToDb()

{

MemoryStream mst =newMemoryStream(); UnicodeEncoding u =newUnicodeEncoding(); string Textn ="Test"; byte[] b = u.GetBytes(Textn);

mst.Write(b ,0,Textn.Length );

BinaryReader reader =newBinaryReader(mst); byte[] file = reader.ReadBytes((int)mst.Length); using (SqlConnection connection =newSqlConnection("Some Connection String"))

{

SqlCommand command =newSqlCommand("INSERT INTO temp (examplefile) Values(@.File)", connection);

command.Parameters.Add(

"@.File",SqlDbType.Binary, file.Length).Value = file;

connection.Open();

command.ExecuteNonQuery();

}

reader.Close();

mst.Close();

}

or with the other method from a real file (not memory stream)

publicstaticvoid Addfile(string path)

{

CommonMethods_class k =newCommonMethods_class(); byte[] file = GetFile(path); using (SqlConnection connection =newSqlConnection(k.Get_connection_string()))

{

SqlCommand command =newSqlCommand("INSERT INTO temp (examplefile) Values(@.File)", connection);

command.Parameters.Add(

"@.File",SqlDbType.Binary, file.Length).Value = file;

connection.Open();

command.ExecuteNonQuery();

}

}

and after running each of them seams that the file have been saved; but I can not retrive the files. I have tried some solutions from msdn but inside the created file is empty. the point that i really look for it is to just working with memory not in the disk before saving. and then retriving each field that I want.

looking forward your points

thank you in advance

Hiashk1860 ,

If you haven't readRead and Write BLOB Data by Using ADO.NET Through ASP.NET you can take a look.

|||

hi

thank you for yor response, Yes, I have read the article and some other Articles and still have problem.

Wednesday, March 7, 2012

Retrieve Query

Hi Friends,
I had written a complex SQL query through SQL Query Analyzer, and had
executed the same by pressing F5 button. Before I could save that query on my
PC, my computer switched off.
By any chance is it possible to retrieve the complex query executed by me ?
If yes then how ?
Thanks and Regards,
AmitUnfortunately, you will have to use your skills to recreate that query. QA
does not have to ability, like the browser, to 'remember' the last thing we
typed in.
Be sure that you have that auto-shut down mechanism turned off next time. I
would absolutely hate it if "my computer switched off" without my telling to
it to do so.
--
Arnie Rowland
"To be successful, your heart must accompany your knowledge."
"Amit20" <Amit20@.discussions.microsoft.com> wrote in message
news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> Hi Friends,
> I had written a complex SQL query through SQL Query Analyzer, and had
> executed the same by pressing F5 button. Before I could save that query on
> my
> PC, my computer switched off.
> By any chance is it possible to retrieve the complex query executed by me
> ?
> If yes then how ?
> Thanks and Regards,
> Amit|||You can not get the query back once it's done running. But let's say while
the query was running your computer got shut down and you had an option to
connect through another machine to same SQL instance then you could use the
following to get the query:
DBCC InputBuffer(spid)
It displays only first 255 characters of your query...
Bob
"Arnie Rowland" wrote:
> Unfortunately, you will have to use your skills to recreate that query. QA
> does not have to ability, like the browser, to 'remember' the last thing we
> typed in.
> Be sure that you have that auto-shut down mechanism turned off next time. I
> would absolutely hate it if "my computer switched off" without my telling to
> it to do so.
> --
> Arnie Rowland
> "To be successful, your heart must accompany your knowledge."
>
> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> > Hi Friends,
> >
> > I had written a complex SQL query through SQL Query Analyzer, and had
> > executed the same by pressing F5 button. Before I could save that query on
> > my
> > PC, my computer switched off.
> >
> > By any chance is it possible to retrieve the complex query executed by me
> > ?
> > If yes then how ?
> >
> > Thanks and Regards,
> > Amit
>
>|||Or profiler was running, or ...
But for all practical purposes, the OP is SOL.
--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:DC9E8CBA-5BD2-480C-8B53-E332F1CB3FEE@.microsoft.com...
> You can not get the query back once it's done running. But let's say while
> the query was running your computer got shut down and you had an option to
> connect through another machine to same SQL instance then you could use
> the
> following to get the query:
> DBCC InputBuffer(spid)
> It displays only first 255 characters of your query...
>
> Bob
> "Arnie Rowland" wrote:
>> Unfortunately, you will have to use your skills to recreate that query.
>> QA
>> does not have to ability, like the browser, to 'remember' the last thing
>> we
>> typed in.
>> Be sure that you have that auto-shut down mechanism turned off next time.
>> I
>> would absolutely hate it if "my computer switched off" without my telling
>> to
>> it to do so.
>> --
>> Arnie Rowland
>> "To be successful, your heart must accompany your knowledge."
>>
>> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
>> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
>> > Hi Friends,
>> >
>> > I had written a complex SQL query through SQL Query Analyzer, and had
>> > executed the same by pressing F5 button. Before I could save that query
>> > on
>> > my
>> > PC, my computer switched off.
>> >
>> > By any chance is it possible to retrieve the complex query executed by
>> > me
>> > ?
>> > If yes then how ?
>> >
>> > Thanks and Regards,
>> > Amit
>>

Retrieve Query

Hi Friends,
I had written a complex SQL query through SQL Query Analyzer, and had
executed the same by pressing F5 button. Before I could save that query on m
y
PC, my computer switched off.
By any chance is it possible to retrieve the complex query executed by me ?
If yes then how ?
Thanks and Regards,
AmitUnfortunately, you will have to use your skills to recreate that query. QA
does not have to ability, like the browser, to 'remember' the last thing we
typed in.
Be sure that you have that auto-shut down mechanism turned off next time. I
would absolutely hate it if "my computer switched off" without my telling to
it to do so.
Arnie Rowland
"To be successful, your heart must accompany your knowledge."
"Amit20" <Amit20@.discussions.microsoft.com> wrote in message
news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> Hi Friends,
> I had written a complex SQL query through SQL Query Analyzer, and had
> executed the same by pressing F5 button. Before I could save that query on
> my
> PC, my computer switched off.
> By any chance is it possible to retrieve the complex query executed by me
> ?
> If yes then how ?
> Thanks and Regards,
> Amit|||You can not get the query back once it's done running. But let's say while
the query was running your computer got shut down and you had an option to
connect through another machine to same SQL instance then you could use the
following to get the query:
DBCC InputBuffer(spid)
It displays only first 255 characters of your query...
Bob
"Arnie Rowland" wrote:

> Unfortunately, you will have to use your skills to recreate that query. QA
> does not have to ability, like the browser, to 'remember' the last thing w
e
> typed in.
> Be sure that you have that auto-shut down mechanism turned off next time.
I
> would absolutely hate it if "my computer switched off" without my telling
to
> it to do so.
> --
> Arnie Rowland
> "To be successful, your heart must accompany your knowledge."
>
> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
>
>|||Or profiler was running, or ...
But for all practical purposes, the OP is SOL.
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:DC9E8CBA-5BD2-480C-8B53-E332F1CB3FEE@.microsoft.com...[vbcol=seagreen]
> You can not get the query back once it's done running. But let's say while
> the query was running your computer got shut down and you had an option to
> connect through another machine to same SQL instance then you could use
> the
> following to get the query:
> DBCC InputBuffer(spid)
> It displays only first 255 characters of your query...
>
> Bob
> "Arnie Rowland" wrote:
>