Re: [Problem in database]
Post the code you are using to insert a file.
Maybe we could alter that so it works for files from your local system.
Re: [Problem in database]
public void AddNewEquipment(string equipmentName, string fileName, string equipmentDesc, decimal equipmentCost)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("AddNewEquipment", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@EquipmentName", SqlDbType.VarChar, 50);
command.Parameters["@EquipmentName"].Value = equipmentName;
command.Parameters.Add("@Picture", SqlDbType.Image);
command.Parameters["@Picture"].Value = GetImage(fileName);
command.Parameters.Add("@EquipmentDesc", SqlDbType.VarChar, 50);
if (equipmentDesc == "")
{
command.Parameters["@EquipmentDesc"].Value = DBNull.Value;
}
else
{
command.Parameters["@EquipmentDesc"].Value = equipmentDesc;
}
command.Parameters.Add("@EquipmentCost", SqlDbType.Decimal, 10);
command.Parameters["@EquipmentCost"].Value = equipmentCost;
connection.Open();
command.ExecuteNonQuery();
}
}
}
/// <summary>
/// Converting Image to Byte
/// </summary>
/// <param name="fileName"></param>
/// <returns>returns byte[] of image</returns>
public object GetImage(string fileName)
{
byte[] image = null;
if (fileName != "")
{
using (FileStream fs = new FileStream(fileName, FileMode.Open,FileAccess.ReadWrite,FileShare.ReadWrite))
{
BinaryReader reader = new BinaryReader(fs);
image = reader.ReadBytes((int)fs.Length);
fs.Close();
return image;
}
}
return System.DBNull.Value;
}
Re: [Problem in database]
Multiple threads removed. Please only post threads once, thanks.
Re: [Problem in database]
Using that code it should work, since you save the save the filestream to the database.
Does getImage return the content of the file?
Are doesn't your code save the stream you get to the database?
Are you getting an error?
Re: [Problem in database]
it shows the error
"Server was unable to process request. ---> Logon failure: unknown user name or bad password."
Re: [Problem in database]
so the error has nothing to do with the image being local or not.
Which type of database are you using?
How do you connect to your database?
Re: [Problem in database]
i am using Sql server database
Re: [Problem in database]
I think you connect by "windows authentication" on the server. since this doesn't work when you're not on the server itself. You should connect using a database user and password.