|
-
Jul 17th, 2007, 01:09 AM
#1
Thread Starter
Lively Member
[Problem in database]
Hi Friends,
i want to insert the image to sql server 2005 database . My Database in another system(ie Server).. i can insert the image which is in Server .. but i can't access (insert ) the image from local system to server .. plz help me .. How to do this ..
regards
Manju
-
Jul 17th, 2007, 01:23 AM
#2
Fanatic Member
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.
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
Jul 17th, 2007, 01:33 AM
#3
Thread Starter
Lively Member
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;
}
-
Jul 17th, 2007, 01:54 AM
#4
Re: [Problem in database]
Multiple threads removed. Please only post threads once, thanks.
-
Jul 17th, 2007, 02:29 AM
#5
Fanatic Member
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?
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
Jul 17th, 2007, 03:31 AM
#6
Thread Starter
Lively Member
Re: [Problem in database]
it shows the error
"Server was unable to process request. ---> Logon failure: unknown user name or bad password."
-
Jul 17th, 2007, 07:58 AM
#7
Fanatic Member
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?
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
Jul 17th, 2007, 08:02 AM
#8
Thread Starter
Lively Member
Re: [Problem in database]
i am using Sql server database
-
Jul 17th, 2007, 01:30 PM
#9
Fanatic Member
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.
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|