简体   繁体   中英

The wait operation timed out in Entity Framework in seed Method

I have a Asp.Net mvc application with an entity framework. I want run ALTER DATABASE in seed method.

SqlCommand command = new SqlCommand(
     string.Format(@"Alter Database {0}
        Set FileStream (NON_TRANSACTED_ACCESS = Full, Directory_Name = '{0}-Directory')",
            builder.InitialCatalog),
            new SqlConnection(builder.ConnectionString));

command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();

My code doesn't work - the wait operation timed out.

Exception Details:

System.ComponentModel.Win32Exception: The wait operation timed out

What should I do to fix this?

Consider using DbContext s ExecuteSqlCommand method.

protected override void Seed(EfContext11 context)
{
    context.Database.ExecuteSqlCommand("your query");
    base.Seed(context);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM