Code to upload file to DB works locally but fails on production se

R

Raj

I am using VS2005,.NET2.0,C#
User selects a file which is uploaded to SQL database.
This code works when its executed on my development machine. However fails
when run on production IIS server.
Can you let me know where i am wrong?
Thanks

try
{
int filesize = 0;
Stream stream = hiFile.PostedFile.InputStream;
filesize = hiFile.PostedFile.ContentLength;
byte[] filedata = new byte[filesize];
stream.Read(filedata, 0, filesize);
string filename =
System.IO.Path.GetFileName(hiFile.PostedFile.FileName);
string strConn = ConnectionStrings["CONNSTR"].ToString();
SqlConnection myConnection = new SqlConnection(strConn);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
SqlDataReader sqlrdr = null;
try
{
myConnection.Open();
SqlParameter[] p = new SqlParameter[5];

p[0] = new SqlParameter("@id",
Convert.ToInt32("DISTICT_NUMBER"));
p[1] = new SqlParameter("@FileName", filename);
p[2] = new SqlParameter("@FileData", filedata);
p[3] = new SqlParameter("@FileSize", filesize);
p[4] = new SqlParameter("@DateCreated", DateTime.Now);


SqlCommand sqlcmd = new
SqlCommand("[STORED_PROCEDURE_UPLOADFILE]", myConnection);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add(p[0]);
sqlcmd.Parameters.Add(p[1]);
sqlcmd.Parameters.Add(p[2]);
sqlcmd.Parameters.Add(p[3]);
sqlcmd.Parameters.Add(p[4]);

sqlrdr = sqlcmd.ExecuteReader();

}
catch (Exception ex)
{
}
finally
{
myConnection.Close();
sqlrdr.Close();
}
 
G

Guest

I am using VS2005,.NET2.0,C#
User selects a file which is uploaded to SQL database.
This code works when its executed on my development machine. However fails
when run on production IIS server.
Can you let me know where i am wrong?
Thanks

 try
        {
            int filesize = 0;
            Stream stream = hiFile.PostedFile.InputStream;
            filesize = hiFile.PostedFile.ContentLength;
            byte[] filedata = new byte[filesize];
            stream.Read(filedata, 0, filesize);
            string filename =
System.IO.Path.GetFileName(hiFile.PostedFile.FileName);
            string strConn = ConnectionStrings["CONNSTR"].ToString();
            SqlConnection myConnection = new SqlConnection(strConn);
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            SqlDataReader sqlrdr = null;
            try
            {
                myConnection.Open();
                SqlParameter[] p = new SqlParameter[5];

                p[0] = new SqlParameter("@id",
Convert.ToInt32("DISTICT_NUMBER"));
                p[1] = new SqlParameter("@FileName", filename);
                p[2] = new SqlParameter("@FileData", filedata);
                p[3] = new SqlParameter("@FileSize", filesize);
                p[4] = new SqlParameter("@DateCreated", DateTime.Now);

                SqlCommand sqlcmd = new
SqlCommand("[STORED_PROCEDURE_UPLOADFILE]", myConnection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add(p[0]);
                sqlcmd.Parameters.Add(p[1]);
                sqlcmd.Parameters.Add(p[2]);
                sqlcmd.Parameters.Add(p[3]);
                sqlcmd.Parameters.Add(p[4]);

                sqlrdr = sqlcmd.ExecuteReader();

            }
            catch (Exception ex)
            {
            }
            finally
            {
                myConnection.Close();
                sqlrdr.Close();
            }

Just get rid of try..catch to see the error
 
A

Andrew Morton

Just get rid of try..catch to see the error

Gazing into my crystal ball, I reckon the OP has forgotten to set the
permission to execute the procedure STORED_PROCEDURE_UPLOADFILE on the
production server for the account trying to execute it.

No, I've never been caught out by that...<cough>.

Andrew
 
G

Guest

Gazing into my crystal ball, I reckon the OP has forgotten to set the
permission to execute the procedure STORED_PROCEDURE_UPLOADFILE on the
production server for the account trying to execute it.

No, I've never been caught out by that...<cough>.

Andrew

He might forget many things. Either he need to remove try..catch to
test, or he need to put error message in the catch block to get the
entire message:

Response.Write(ex.Message);
 

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

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top