Results 1 to 9 of 9

Thread: [Problem in database]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    [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

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

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

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [Problem in database]

    Multiple threads removed. Please only post threads once, thanks.

  5. #5
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Re: [Problem in database]

    it shows the error

    "Server was unable to process request. ---> Logon failure: unknown user name or bad password."

  7. #7
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Re: [Problem in database]

    i am using Sql server database

  9. #9
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    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
  •  



Click Here to Expand Forum to Full Width