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();
}
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();
}