Wednesday, March 21, 2012

Delay between CREATE DATABASE and ability to connect to that database

I have an application that creates a new database during installation,
and I've noticed some strange behavior. Once I've created the
database, I am able to immediately create tables and populate lookup
data, provided I remain connected to the server. If, however, I
disconnect and attempt to reconnect immediately, I'll get an error
saying that my login is invalid for the new database.

I can get around this by having my code simply wait 5 seconds before
attempting to reconnect, but I'm curious to see if anybody here can
give an explaination for why this is happening. Here is a bit of
pseudo code to explain what I'm seeing:

open new connection
create database
create tables
populate tables
close connection

// open new connection /* can't do this yet, as it would break */

for (int a=0; a<5; a++)
{
Thread.Sleep(2000)
try
{
open new connection
break;
}
catch
{
Debug("still waiting...");
}
}

Running my version of this code, I'll see that "still waiting..."
message go past 2-3 times before SQL Server wakes up and realizes that
I'm allowed to connect to it. Anybody know why?

Thanks,

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
--
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/On 6 Oct 2006 17:36:01 -0700, Jason Kester wrote:

(snip)

Hi Jason,

You posted the same question and youy already received some answers
there.

In the future, please post to a single group only. It prevents people
wasting time on a problm that has already been solved.

--
Hugo Kornelis, SQL Server MVP

No comments:

Post a Comment