473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Saving and retriving images in database through WS

Hi there.

I'm developing a small application that uses Web Services to access database
and store data.

At some point, I store some images, by inserting the absolute image path
into a varchar field (SQL Server 2005). Images themselves are copied to that
path on the server. To read the images, I just use this path.

However, some workstations have to authenticate the server that path. To
avoid other problems, like deleting those images, I want to store images
directly in database, on a Image field.

So, after this long intro, I could have this code on server side (WS), to
save images:

/****/
[WebMethod]
public void SaveImage( string name, byte[] imageData )
{
//use the web.config to store the connection string
SqlConnection connection = new
SqlConnection(ConfigurationSettings.AppSettings["DSN"]);
SqlCommand command = new SqlCommand( "INSERT INTO Image(name, data)
VALUES (@name, @data)", connection );
SqlParameter pName = new SqlParameter( "@name", SqlDbType.VarChar,50 );
pName.Value = name;
command.Parameters.Add( pName );
SqlParameter pData = new SqlParameter( "@data", SqlDbType.Image );
pData.Value = imageData;
command.Parameters.Add( pData );
try
{
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
}
finally
{
connection.Close();
}
}
/****/

and on client side:

/****/
remoteService.ServiceSoapClient srv = new remoteService.ServiceSoapClient();
Image image = Image.FromFile(@"c:\myimage.bmp");
using(MemoryStream stream = new MemoryStream())
{
image.Save( stream );
byte[] buffer = steam.ToByteArray();
srv.SaveImage( "myimage", buffer );
}
/****/

My questions: is this good practice? Is there a better way to do it?

Thanks in advance. Sorry the long post.

Marco
Mar 20 '08 #1
2 1828
Looks like you've got the right idea if you want to do it that way.
You mentioned that you have workstations using this telling me its
potentially an internal app, if thats the case what we did when I had
a similar issue was save the image/file to a shared directory on the
server and put the path to the image in the database.
Mar 20 '08 #2
Right bow, I'm using a shared folder on the server. The problem is that
workstations aren't connected to a domain controler (windows home editons
versions only), and the first time workstations try to access server, thay
must authenticate.

Well, "regular" computer users, can't deal well with this, as you can
imagine.

"cfps.Christian" <ge*******@otc.eduescreveu na mensagem
news:d1**********************************@q78g2000 hsh.googlegroups.com...
Looks like you've got the right idea if you want to do it that way.
You mentioned that you have workstations using this telling me its
potentially an internal app, if thats the case what we did when I had
a similar issue was save the image/file to a shared directory on the
server and put the path to the image in the database.

Mar 20 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TheTenor | last post by:
I have a page with a graphic. I want to be able to define the graphics such that it is not saved when the viewer saves the page to his local drive. I'm trying to avoid having a seperate folder...
1
by: MIchael McDowell | last post by:
Anyidea how this might be done using and XML Web Service and the XMLSerialzation class? A pointer to an online example would be deeply appreciated. Thankyou in advance, Michael McD
3
by: sameer | last post by:
Hi all, ..net framwork 1.1 sql server 2000 I have a vb.net winforms application using webservices\ remoting to upload documents\ images to the webserver and i am gong to store them in the sql...
0
by: sameer | last post by:
Hi all, ..net framwork 1.1 sql server 2000 I have a vb.net winforms application using webservices\ remoting to upload documents\ images to the webserver and i am gong to store them in the sql...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
3
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
2
by: carj2ee | last post by:
I trying to write a program that will go to a website and get all the images and then save then on to a local drive. I am using a mshtml.HTMLImg variable and then directcasting the web page to...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
10
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.