There are two fixes.
This is "wrong".
cmd.Parameters.Add(new SqlParameter("@img", data));
This works.
cmd.Parameters.Add("@img", SqlDbType.Image);
p.Value =3D data;
Requests greater than 4 MB aren't handled by .NET, but you can change
that setting.
http://support.microsoft.com/default.aspx?scid=3Dkb;en-us;Q295626
Andrew
-----Original Message-----
From: Andrew Bradnan
Sent: Monday, September 23, 2002 5:52 PM
To: ASPX_Professional
Subject: [aspx_professional] Storing SQL images
I'm following most of the examples I've seen. They work great till
about 500 KB then I get 'A severe error occurred on the current command.
The results, if any, should be discarded.'
A little bigger and I get a "general network error", not even a
SQLException.
Bigger still and I get a default 404 page, .NET falls over completely.
I don't even hit my Page_Error code.
Anyone gotten around this?
Here's my code.
HttpPostedFile f =3D postedfile.PostedFile;
Stream s =3D f.InputStream;
String sName =3D f.FileName;
byte[] data =3D new byte[f.ContentLength - 1];
s.Read(data, 0, f.ContentLength-1);
// Remove the file path
int nSlash =3D sName.LastIndexOf('\\');
if (nSlash !=3D -1)
sName =3D sName.Substring(nSlash, sName.Length-nSlash);
SqlConnection cnn =3D new SqlConnection(user.strConnect);
cnn.Open();
SqlCommand cmd =3D new SqlCommand(
"insert into dbo.[file] values(0,'"
+ sName +"','"
+ f.ContentType + "', @img)", cnn);
cmd.Parameters.Add(new SqlParameter("@img", data));
cmd.ExecuteNonQuery();
Thanks,
Andrew
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---