Home > database >  EF 6 | Timeout error on inserting into database, but works fine on another computer
EF 6 | Timeout error on inserting into database, but works fine on another computer

Time:05-25

I'm working with a friend on a project. I am now running the code on my system, but for me, I receive this error when I try to create a record in the SQL server database.

enter image description here

When he runs it on his system, it updates without any issues.

If I add this code to the context startup it works for me, but takes time!

        public FileContext()
            : base("name=FileContext")
        {
            var adapter = (IObjectContextAdapter)this;
            var objectContext = adapter.ObjectContext;
            objectContext.CommandTimeout = 1 * 60; // value in seconds
        }

What is set wrong that would cause this?

We shouldn't have to touch the timeout if it works on his computer and has for this entire time?

Update:

The GET call to the database on the same table is working fine, but the inserts into the table cause timeouts.

Update 2: After the below comment, I took the query directly to SQL Server and it takes 40 seconds on the server. It is a simple insert statement. On another database, it works fine.

CodePudding user response:

Fixed:

I had to rebuilt the Indexes on the table that was seeing the slowness into SQL Server.

Went to SSMS -> Databases -> problematic Table -> Indexes -> Rebuild indexes

enter image description here

  • Related