Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-12-17 : 09:03:05
|
| Claude writes "I am unable to properly retrieve RAISERROR errors from VB code. The basis:Win2000, SQL2000, MDAC 2.7 provider SQLOLEDB.1, VB6 Test proc:CREATE PROCEDURE test ( @v as varchar(20) output )ASdeclare @err intSELECT @v= 'before'RAISERROR('An error',16,1)SELECT @err=@@ErrorSELECT @v= 'after'RETURN (@Err)From VB6:Works:VB error is raised with 'An error' messagep(1) = 'after'p(0)= 50000Doens't work:activeConnection.errors always empty ???I tested the cursorLocation client and server without any better results.PRINT is not helping. When placed before the raiserror is never raised in VB. When place after the message is not availaible in VBAny help would be appreciated.Regards. CL" |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2001-12-17 : 13:38:38
|
| @@Error traps the error number of the MOST RECENTLY EXECUTED STATEMENT. So, in your example, it is trapping any error that occurred during the RAISEERROR command. See this article for more info: [url]http://www.sqlteam.com/item.asp?ItemID=6881[/url]-------------------It's a SQL thing... |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2001-12-17 : 16:59:52
|
| Claude,I found that the best way to trap any error from SQL Server through VB/ADO is to use the connection object "WithEvents"eg.'<VB>Private withevents mCNN as ADO.Connection'The event stubs of most use are the following' ConnectComplete and ExecuteCompletePrivate Sub mCNN_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)On Error Resume NextIf adStatus = adStatusErrorsOccurred Then RaiseErr "Connection Failed", pError.Description, pError.NativeError, pError.SourceEnd If End Sub'Check Execution OKPrivate Sub mCNN_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)On Error Resume NextIf adStatus = adStatusErrorsOccurred Then RaiseErr "Execution Failed", pError.Description, pError.NativeError, pError.SourceEnd IfEnd Sub'</VB>Hope this HelpsDavidM"Why are you crying?""Because I love a Microsoft product" |
 |
|
|
|
|
|
|
|