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 2005 Forums
 .NET Inside SQL Server (2005)
 Database attached but unable to connect

Author  Topic 

Jawad Khan
Starting Member

21 Posts

Posted - 2009-05-12 : 12:39:42

I am trying to connect to a database and in case of failure, The database is attached and the connection is re-established. The database is connected successfully (I can see it is attached in Management Studio).

If I insert a delay loop after the attachDatabase, then it works successful. I want to ask that what is the standard way to wait for a database to be attached?

Thanks

try
Dim Srv As Server = New Server(srvName)
Srv.ConnectionContext.LoginSecure = True
Srv.ConnectionContext.DatabaseName = dbName

srv.ConnectionContext.Connect()

Catch ex As Exception
AttchDatabase() 'The databse is succesfully attached.
'Now try connecting again, and hope it is successful
Dim Srv As Server = New Server(srvName)
Srv.ConnectionContext.LoginSecure = True
Srv.ConnectionContext.DatabaseName = dbName



'The line below throws an exception that 'Unable to connect'


srv.ConnectionContext.Connect()
End Try
   

- Advertisement -