Problem ...

J

Jacek Jurkowski

.... I'm trying to retrieve an Image from Image field
of a remote SQLServer Table.

The code is simple:

SqlConnection c = new SqlConnection("Data
Source=XX.XX.XXX.XX;Initial Catalog=STFManager;Persist Security
Info=True;User ID=XXXX;password=XXXX");
c.Open();
SqlCommand sc = new SqlCommand("select photo from images where
id = 'ce35d01b-5201-42b1-819b-300edc0d3daf'", c);
SqlDataReader r = sc.ExecuteReader();
r.Read();
f.e:) MessageBox.Show(r[0].ToString());
r.Dispose();
c.Close();
return;

Everytime doing that I got a timeout exception regardless of the
size of an image. It could be caused by the network slowness or
lags but the same command executed by SQLServer Query designer runs
almoust imediatelly ...

What's wrong? Some bug may be?
 
G

Guest

What's the r[0].ToString() ?!
If you are getting Image you need to use array of bytes

.... I'm trying to retrieve an Image from Image field
of a remote SQLServer Table.
The code is simple:
SqlConnection c = new SqlConnection("Data
Source=XX.XX.XXX.XX;Initial Catalog=STFManager;Persist Security
Info=True;User ID=XXXX;password=XXXX");
c.Open();
SqlCommand sc = new SqlCommand("select photo from images where
id = 'ce35d01b-5201-42b1-819b-300edc0d3daf'", c);
SqlDataReader r = sc.ExecuteReader();
r.Read();
f.e:) MessageBox.Show(r[0].ToString());
r.Dispose();
c.Close();
return;

Everytime doing that I got a timeout exception regardless of the
size of an image. It could be caused by the network slowness or
lags but the same command executed by SQLServer Query designer runs
almoust imediatelly ...

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
J

Jacek Jurkowski

I do. r[0] is a first column in the query result wchich is
array of bytes. MessageBox is not important. The problem is
that the DataReader isn't filled because the timeout error...
Here's anodher piece of code without Messagebox but
stil isn't working:

SqlConnection c = new SqlConnection("Data Source=62.69.192.75;Initial
Catalog=STFManager;Persist Security Info=True;User
ID=Jacek;Password=payne;Packet Size=4096");
c.Open();
SqlCommand cmd = new SqlCommand("select photo from images",c);
SqlDataReader r = cmd.ExecuteReader();
r.Read();
Byte[] image = (Byte[])r["photo"];
r.Close();
c.Close();

The same command throught Query analyzer runs fine ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top