I need to figure out how I can detect whether or not a database exists on my SQL 2000 server from ASP. The reason is that I want to drop a database only if it exists. Any help would be appreciated! Thanks!
If you are going to drop the database anyway, why bother testing for it?<BR><BR>Just do a "on error resume next" and drop the database. If it exists, then it will be deleted, if not the error will be ignored.<BR><BR>Oh, and don't forget to do an "on error goto 0" after to turn error handling back on again.
So are you suggesting this...<BR><BR>on error resume next<BR>strSQL = "DROP DATABASE " & dbName<BR>objConn.Execute(strSQL)<BR>on error goto 0<BR><BR>This would be okay and would still cature errors happening later on in the code?<BR>
If you use SQL Server's Generate Script tool on the database itself, it will generate the SQL to see if it exists and perform a DROP on it.<BR><BR>put the 3 or 4 lines of code from the script into your own stored procedure and execute it from ASP/ADO.
The app is building dynamic web sites complete with their own databases. Whenever I "publish" a site, it will drop the database and recreate it with any new parameters. Is there a more optimal way of doing this? This doesn't seem like "crappy" logic to me.<BR><BR>Does the other individuals suggestions work though? i.e. use on error resume next and then resetting it after the drop statement?<BR><BR>