1

In my Global.asax file, under my ApplicationStart() function I want to drop a table and recreate it cleanly when application starts. What is the best way to accomplish this so it is seamless every time i start my program? To get a better idea, I am keeping track of online users in a table, but when the application starts up again, obviously I would like to clear this table out. I need to drop and recreate the table because the identity seed won't start over if i simply truncate it (I am using sql azure so i cannot run a db command to reset the seed). Also, if i did just truncate my table, would not resetting the seed be a bad practice? I've done this and im already at like id 1000, just after testing.

3
  • This might help: social.msdn.microsoft.com/Forums/en/adonetefx/thread/… Commented Sep 13, 2012 at 22:17
  • Not resetting the seed wouldn't be a bad practice at all, if you don't need the actual ID to be sequentially numbered. If you are afraid you will run out of IDs, you could increase the field length or use a GUID field instead. Commented Sep 13, 2012 at 22:21
  • 2
    Actually a SQL TRUNCATE TABLE command does reset the seed of an identity column. It's DELETE FROM that doesn't. Can you show your current code that clears the table? Commented Sep 13, 2012 at 23:16

1 Answer 1

1

You can do a normal SQL TRUNCATE command, using the ExecuteStoreCommand method. Just like this dbContext.ExecuteStoreCommand("TRUNCATE TABLE myTable"); . Truncate deletes all records from table and resets the seed for auto id.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.