Something like this should do the trick:
Dim SqlCon As SqlConnection
Dim DatabaseExists As Boolean = True
Try
SqlCon = New SqlConnection("SERVER=(local);" & _
"INITIAL CATALOG=database_name;" & _
"USER ID=mcoles;PASSWORD=1qaz1qaz;")
SqlCon.Open()
Catch ex As SqlException
If ex.Number = 4060 Then
DatabaseExists = False
Else
Throw (ex)
End If
Finally
If Not (SqlCon Is Nothing) Then
SqlCon.Dispose()
End If
End Try
"Jon" <Jo*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
hi,
Could anyone pls tell me what is the best way to check if a database exist
on the SQL server or not?
any example code would be appreciated!
many thanks in advance.
Jon