How to catch a SqlException?
-
Hi, this is my code: Try Dim DbTest As SqlClient.SqlConnection DbTest = New System.Data.SqlClient.SqlConnection("Data Source=(local)\SQL;Initial Catalog=testiranje123;Trusted_Connection=yes;Integrated Security=True;Asynchronous Processing=true") DbTest.Open() DbTest.Close() Catch ex As SqlException MsgBox("idemo dalje") Catch ex As DataException MsgBox("idemo dalje") Catch ex As Exception MsgBox("idemo dalje") End Try the connection string is wrong, i did this on purpose. So i can catch the exception and handle it and build a connection string change mechanism... the exception is: SqlException: Cannot open database "testiranje123" requested by the login. The login failed. Login failed for user 'test\test'. There is no way I could catch the exception. I tried all kinds of catch exception handlers but no luck the exception just keeps showing up. Please, if anybody knows the answer, it is urgent. Thank you very much!
-
Hi, this is my code: Try Dim DbTest As SqlClient.SqlConnection DbTest = New System.Data.SqlClient.SqlConnection("Data Source=(local)\SQL;Initial Catalog=testiranje123;Trusted_Connection=yes;Integrated Security=True;Asynchronous Processing=true") DbTest.Open() DbTest.Close() Catch ex As SqlException MsgBox("idemo dalje") Catch ex As DataException MsgBox("idemo dalje") Catch ex As Exception MsgBox("idemo dalje") End Try the connection string is wrong, i did this on purpose. So i can catch the exception and handle it and build a connection string change mechanism... the exception is: SqlException: Cannot open database "testiranje123" requested by the login. The login failed. Login failed for user 'test\test'. There is no way I could catch the exception. I tried all kinds of catch exception handlers but no luck the exception just keeps showing up. Please, if anybody knows the answer, it is urgent. Thank you very much!
-
You mean that when you run that code the msgbox never appears? instead it stops at DbTest.Open with an exception?
Yes, that is what I mean, Thank you. I can not catch the exception it keeps showing up. But i want to catch it and handle it. The msgbox is just a test to see if it can catch it. But the msgbox never shows up. Please, if you know the answer share it with me! Thank you.