.net - C# string match based on wildcards -
i getting database exception
database 'db_name' cannot opened. in middle of restore
try { } catch(exception ex) { if(ex.message.contains("database 'db_name' cannot opened. in middle of restore")){ //show user friendly message } }
but problem have around 10-15 database names , keep adding more.
how match string has wildcard?
is there regex match database '{whatevercomes}' cannot opened. in middle of restore
you should handle sqlexception
instead of exceptions. differentiate between errors via number
property. error 927.
here find all: http://technet.microsoft.com/en-us/library/aa937592(v=sql.80).aspx
try { // ... } catch(sqlexception ex) { if(ex.number == 927) { //show user friendly message } }
according actual name of database: seems not possible retrieve sqlexception
. since message change due localization, why can't handle exception you've opened connection? use sqlconnection.database
-property.
for example:
using (var con = new sqlconnection("connection-string")) { try { con.open(); // ... } catch (sqlexception ex) { string database = con.database; if (ex.number == 927) { //show user friendly message string errormessage = string.format("could not open database '{0}' since it's restoring. please inform database administrator." , database); messagebox.show( errormessage ); } } }
Comments
Post a Comment