Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Creating database via queries

Author  Topic 

figmo
Starting Member

18 Posts

Posted - 2010-10-14 : 09:34:14
I have a series of script commands that I call via a series of queries that creates my schema.

1. The first query checks the database and if it does not exist it creates it.

2. The next query checks for my first table, and if it does not exists it creates it (and any needed indicies/triggers)

(...This is repeated for my remaining tables.)

All works fine but I think I'm running into a "race condition" problem.

It seems when I execute these back to back - the first query runs without problem (creating the DB), but the 2nd query gives me an error that the DB does not exist.

If I re-run this same series of scrips, all is fine. (first query sees DB exists and does nothing, all remaining queries create their tables as normal)

So my suspicion is that somehow the DB has not finished being created between the time that the 1st query ends and the 2nd begins.

Am I on the right track? Is there a way to "wait" for completion of a command in SQL Server 2008?

BTW - I'm calling these one after the other from c# using ExecuteNonQuery()

figmo
Starting Member

18 Posts

Posted - 2010-10-14 : 10:32:18
IGNORE ABOVE POST......It was a typo in my code....damn....I just *HATE IT* when that happens.....

{trying to slink out the door without being noticed}
Go to Top of Page
   

- Advertisement -