Hi!
How may I find out if a specific SQL Server database exist or not, through a VB.NET application?
Much obliged to you for your attention. Regards!
I'm sure there are better methods, but I check by error trapping.
Try
'connect to SQL server
Catch ex As System.Data.SqlClient.SqlException
'Schauen ob SQL Server existiert...
'HACK
If CType(ex, System.Data.SqlClient.SqlException).Number = 17 Then
Response.Write("SQL Server connection problem")
Response.End()
End If
End Try
Well as I said it's not very elegant but seems to work.
Look up the error numbers inmaster.dbo.sysmessages
|||Why not just query master.dbo.sysdatabases ?|||
Ooops, my bad.
I misread the question, thought you were looking for code to check Server existance, not databse.
|||Here is some VBS code to enumerate the servers on a network... You should be able to adapt this to see if a server exists:Set oSQLApp = createobject("SQLDMO.Application")
Set oNames = oSQLApp.ListAvailableSQLServers()
For i = 1 To oNames.Count
msgbox(oNames.Item(i))
Next
|||Thanks that's worth investigatingsql
No comments:
Post a Comment