So, I'm trying to a server and I'm moving a website from an older server to a new one. It's changing from 32-bit to 64-bit. The developer (who is no longer here) coded the webstie to upload PDF documents and save them in an Image field. Works great, but not on the new server.
The following code is the page that gets called to display the PDF. Ex: TestMethod.aspx?id=75
<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.Buffer = true;
SqlCommand cmd = new SqlCommand("SELECT method FROM Tests WHERE id = @id");
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Util.GetBLOB(cmd, Response.OutputStream, 32768);
Response.Flush();
Response.End();
}
</script>
The GetBLOB function is as follows:
public static void GetBLOB(SqlCommand cmd, Stream output, int bufferLength)
{
byte[] outbytes = new byte[bufferLength];
SqlConnection connex = new SqlConnection(ConfigurationSettings.AppSettings["DSN"]);
cmd.Connection = connex;
connex.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
rdr.Read();
int start = 0;
long retval = rdr.GetBytes(0, 0, null, 0, 0);
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
while (retval > 0)
{
output.Write(outbytes, 0, (int)retval);
start += outbytes.Length;
retval = rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
}
retval = rdr.GetBytes(0, start, null, 0, 0);
outbytes = new byte[retval];
rdr.GetBytes(0, start, outbytes, 0, outbytes.Length);
output.Write(outbytes, 0, (int)retval);
connex.Close();
}
I am very new to ASP.NET and cannot see a simple solution. Does this have anything to do with the server being 64 bit? Thanks for any help.
I get the following error when run:
Specified argument was out of the range of valid values.
Parameter name: offset
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset
Source Error:
Line 14: SqlCommand cmd = new SqlCommand("SELECT document FROM TechLibrary WHERE id = @id");
Line 15: cmd.Parameters.Add("@id", SqlDbType.Int).Value = Int32.Parse(Request["id"]);
Line 16: Util.GetBLOB(cmd, Response.OutputStream, 32768);
Line 17:
Line 18: Response.Flush();
Source File: d:\....\TechLibraryDoc.aspx Line: 16
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset]
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) +169
trace.Util.GetBLOB(SqlCommand cmd, Stream output, Int32 bufferLength) in c:\Inetpub\wwwroot\trace\src\Util.cs:146
ASP.techlibrarydoc_aspx.Page_Load(Object sender, EventArgs e) in d:\.....\TechLibraryDoc.aspx:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603
Version