Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:58:58+00:00 2026-05-17T23:58:58+00:00

I have a web application which is giving me the following exception: InnerException {Cannot

  • 0

I have a web application which is giving me the following exception:

InnerException {“Cannot insert
explicit value for identity column in
table ‘Cover’ when IDENTITY_INSERT is
set to OFF.”} System.Exception
{System.Data.SqlClient.SqlException}

I’m trying to insert into a database which looks like the following:

dbo.File
FileID            int  PK
Title             nvarchar(50)
ISBN              nvarchar(50)
UploadDate        datetime
UserName          nvarchar(50)

dbo.Cover
CoverID           int PK
CoverFileContent  varbinary(max)
CoverMimeType     nvarchar(50)
CoverFileName     nvarchar(50)
FileID            int FK

dbo.Cover
CoverID           int  PK
CoverFileContent  varbinary(max)
CoverMimeType     nvarchar(50)
CoverFileName     nvarchar(50)
FileID            int FK

In this database the File table has a one to many relationship with both the Cover, and the Pdf table. In my application, the user first enters a description of the file, and this updates the file table, then they upload a picture associated with the file which updates the Cover table, and then they upload a PDF file (I have not got this far yet).

Right now, my MVC c# code looks like the following:

FileController

 //
    //GET: /File/CreateFile
    public ActionResult CreateFile()
    {
        File file = new File();

        return View(file);
    }

//
//POST: /File/CreateFile
[HttpPost]
public ActionResult CreateFile(FormCollection formvalues)
{
    File file = new File();

    if (TryUpdateModel(file))
    {
        filerepository.AddFileData(file);
        filerepository.Save();

        return RedirectToAction("CreateCover", "Cover", new { id = file.FileID });
    }

    return View(file);
}

Cover Controller

//
        //GET: /File/CreateCover
        public ActionResult CreateCover(int id)
        {
            Cover cover = new Cover();
            cover.FileID = id;
            return View(cover);
        }

        //
        //POST: /File/CreateCover
        [HttpPost]
        public ActionResult CreateCover(Cover cover)
        {
            cover.CoverMimeType = Request.Files["CoverUpload"].ContentType;
            Stream fileStream = Request.Files["CoverUpload"].InputStream;
            cover.CoverFileName = Path.GetFileName(Request.Files["CoverUpload"].FileName);
            int fileLength = Request.Files["CoverUpload"].ContentLength;
            cover.CoverFileContent = new byte[fileLength];
            fileStream.Read(cover.CoverFileContent, 0, fileLength);
            cover.FileID = int.Parse(Request.Form["FileID"]);
            filerepository.AddCoverData(cover);

            filerepository.Save();

            return View(cover);
            //return View("CreatePdf", "Pdf", new { id = cover.FileID });
        }

CreateCover View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SampleApp.Models.Cover>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    CreateCover
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" 

runat="server">

        <h2>CreateCover</h2>

        <% using (Html.BeginForm("CreateCover", "Cover", FormMethod.Post, new { enctype = "multipart/form-data" }))
           { %>
           <%: Html.HiddenFor(model => model.FileID) %>
        <asp:Label ID="Label2" runat="server" Text="Please Select your eBook Cover" /><br />
        <input type="file" name="CoverUpload" /><br />
        <input type="submit" name="submit" id="Submit" value="Upload" />

        <% } %>

        <div>
            <%: Html.ActionLink("Back to List", "Index") %>
        </div>

    </asp:Content>

I was able to upload a cover once, however ever since then I’ve been getting this error. I noticed that in my table I had forgotten to set the PK column as IDENTITY (1, 1), however I changed this and am still getting the error.

I also don’t know if it’s worth mentioning, but in my database for the one image I was able to upload, the binary content in the database is pretty much “0x00000….”…This seems wrong? 🙂

Any help or advice would be appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:58:58+00:00Added an answer on May 17, 2026 at 11:58 pm

    Solved this issue for anyone else who is having the same problem. Simply refreshed the model in Visual Studio and it seems to have done the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have web application which we deployed in a production . We have separate
I have web application of which major part is javascript. I request images from
I have a web application which process the data collected from different client machines
I have a web application which uses the globalization values being passed from sql
I have a web application which needs to perform a file copy operation and
I have one web application which I have been working for some time.I am
I have a web application which contains both secure (SSL) and non-secure pages. A
I have a web application which is deployed by the means of Flask. I'm
Using JDeveloper as my IDE, I have a web application which calls services provided
I have a simple web application which lets the user upload local user data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.