How can SMO retrieve the SQL messages from ExecuteNonQuery(SQLFile)

I have a vb.net app that uses SMO to execute SQL files with the ExecuteNonQuery(SQLFile). The ExecuteNonQuery(SQLFile) is in a TRY CATCH and I catch SQLException, SMOException, and general Exception. When my SQL file has an error, such as a table name that
does not exists, it throws a general Exception and the message is "An exception occurred while executing a Transact-SQL statement or batch." I want the message that would be shown on the Messages pane in SSMS "Msg 2812, Level 16, State 62, Line
2. Could not find stored procedure 'ifs_RunHistoryInsertv2x'."
How can I get the Msg from SQL returned to SMO so that I can show is in a messagebox?

How could I do something like this in Powershell?
I've tried something like this:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
# Create SMO Server Object
$Server = New-Object ('Microsoft.SQLServer.Management.Smo.Server') "SD-KP-DEVSUP01\KP"
#AddHandler $Server.ConnectionContext.InfoMessage, New SqlInfoMessageEventHandler(AddressOf OnInfoMessage)
$db = $Server.Databases["master"]
try {
$db.ExecuteWithResults("SELECT name from sys.databases2").Tables[0]
catch [Exception] {
$_.Exception|fl -Force
#[SqlException]$se=$_.Exception.InnerException
and I get this Error:
SmoExceptionType : FailedOperationException
Operation : Execute with results
FailedObject : [master]
Message : Execute with results failed for Database 'master'.
HelpLink : http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=12.0.2000.8+((SQL14_RTM).140220-1752)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Exec
ute+with+results+Database&LinkId=20476
Data : {HelpLink.ProdName, HelpLink.BaseHelpUrl, HelpLink.LinkId, HelpLink.ProdVer...}
InnerException : Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Invalid object name
'sys.databases2'.
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteWithResults(String sqlCommand)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteWithResults(String sqlCommand)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteWithResults(StringCollection sqlCommands)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteWithResults(StringCollection query)
at Microsoft.SqlServer.Management.Smo.Database.ExecuteWithResults(StringCollection sqlCommands)
TargetSite : System.Data.DataSet ExecuteWithResults(System.Collections.Specialized.StringCollection)
StackTrace : at Microsoft.SqlServer.Management.Smo.Database.ExecuteWithResults(StringCollection sqlCommands)
at CallSite.Target(Closure , CallSite , Object , String )
Source : Microsoft.SqlServer.Smo
HResult : -2146233088
I've looked at all the items in $_ and $Error[0] but can't find any reference to what actual script line failed.
I really want to do output something like this to get more details where the error happened in a big script file.
Console.WriteLine("Msg {0}, Level {1}, State {2}, Line {3}", e.Number, e.Class, e.State, e.LineNumber)

Similar Messages

  • I accidentally deleted all my husband's Mac mail and now it is also gone from his gmail account. How can I retrieve the deletd messages?

    I accidentally deleted all my husband's Mac mail and now it is also gone from his gmail account. How can I retrieve the deletd messages?

    Did you also empty the trash can?   If you did not empty the trash, then likely mail moved the messages to the trash folder on GMAIL.

  • How can we retrieve the Payload information from B2B

    Hello,
    We are trying to send the payload information back to the client for a failed BPEL Transaction from B2B's b2b_instancemessage view. We are enqueing messages to IP_OUT_QUEUE using BPEL. We see the payload coming correctly in the B2B Business Message Reports. But we don't see the payload coming in the b2b_instancemessage view for failed B2B transactions. How can we see the payload in b2b_instancemessage view for failed B2B transactions as well? or How can we retrieve the Payload information from B2B?
    Any help is greatly appreciated! Thanks. - Sam.
    Edited by: user12049162 on Dec 4, 2009 2:04 PM

    I am not sure about the PDK API to get the group name. But using LDAP API its easy to get the User Group.
    If you find the answer to get the group name using PDK API, Please update in forum. It will really help others.
    --Balaji S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can I Fetch the error message from a OAF page

    Hi,
    A confirmation message is coming on the page,I want to catch the error message and depending on its value want to add some validation.
    Is that possible to fetch the error message from the page?

    is it a confirmation message or an error message ?
    Code in the OAF page would be raising an OAException with a message name defined in message dictionary.
    you would need to look at the code to understand where this is thrown from and add your validation there.
    Tapash

  • How can I retrieve deleted text messages from my iphone 5

    Somebody deleted a string of text messages from my iPhone 5 and I want to know if they can be retrieved and if so how? I'm new to the iPhone as this is my first apple product.  I am still not even sure on how to use my iTunes and so forth.  Please help as the string of messages was very important!! Thank you so very much!! Tracy

    SMS text messages are backed up with the iPhone - whether it's locally or to iCloud. If you've already written over the backup that had them (as in, backed up after the delete) then they're gone.
    If you still have a backup available from a time where you had the messages on your iPhone, all you have to do is erase the iPhone and restore from that backup.
    "Retrieve deleted messages from iPhone" is simple as pie.

  • How can i get the error message from the thrown/raised exception?

    DB version:10gR2
    Examples for this thread taken from
    Want Stored Procs to get exectuted regardless of preceeding SPs Success or
    I have a package with several functions and procedures inside.I created a caller procedure called callProcs, which will execute various procedures within the package in the appropriate order.
    In the below example i cannot get the error message thrown from line 20
    create or replace package body mypackage
    is
    variable_proc1 number;
    variable_proc2 number;
    variable_proc3 number;
    v_result       number;
    my_exception   exception;
    procedure proc1
    is
    begin
    select 8/0 into variable_proc1 from dual;
    exception
              when others
              then raise my_exception; ----line 20
    end;
    procedure proc2
    is
    begin
    select 1 into variable_proc2 from dual;
    exception
              when others
              then
                   null;
    end;
    procedure proc3
    is
    begin
    select 3 into variable_proc3 from dual;
    exception
              when others
              then
                   null;
    end;
    Procedure caller_proc
    is
    begin
    proc1;
    proc2;
    proc3;
    v_result:=variable_proc2+variable_proc3;
    dbms_output.put_line('The output is '||v_result);
    exception
              when my_exception
              then
    dbms_output.put_line('Heyyyyy the error is '||SQLERRM); -- exception caught at line 64 of caller proc
    end;
    end mypackage;
    When i try executing the caller proc, i don't get the error. Instead i get the text User-Defined Exception as shown below
    set serveroutput on
    exec mypackage.caller_proc;
    Heyyyyy the error is User-Defined Exception
    PL/SQL procedure successfully completed.Edited by: user10633418 on Mar 10, 2009 11:30 PM

    Thank you justin.
    Sorry my earlier post was a bit ambiguous.
    I wanted the error generated at proc1 to be captured at caller proc's Exception handling section (line 64) so that i could log the error to an ERR_LOG table.
    I can actually log this error at proc1 itself like
    exception
    when others
    THEN
    error_message :='My custom message for the particular proc '||SQLERRM;
    dbms_output.put_line(error_message);
    logerror(error_message); --an autonomous error logging proc
    raise;But there is a RAISE statement in proc1's exception handling, so the exception gets propogated to caller proc's exception handling section {color:#ff0000}*and another redundant row will be created at ERR_LOG table for the same error because there is a*{color}
    logerror(error_message);--an autonomous error logging proc
    in the WHEN OTHERS section of exception handling section of the caller proc
    I want to avoid the creation of this redundant row in ERR_LOG table.

  • Unable to clear inbox, still showing 1 message in inbox on icon when there are no messages in the inbox. How can I clear the 1 message from the icon indicator?

    I am unable to clear 1 message in my email inbox showing on the icon. I have tried clearning out all messages in my inbox and it still shows 1 message remaining unread. I erased messages 5 days ago and since then it has been showing 1 message remaining. How can I clear this from the icon? Thanks

    Ouit Mail app. (Remove from MultiTasking bar).
    Double tap the home button to bring up the multitasking dock. Tap and hold an app. A red badge with a minus symbol will appear on the icons. Tap the minus symbol of Mail app to quit.

  • How can we retrieve the Group name from oid?

    Hi:
    In following request object, we can get all the user related information from oid except group name where a particular user belongs to.
    For instance user id, first name, last name and email etc but we could not get the group name.
    PortletRenderRequest pReq = (PortletRenderRequest)
    request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
    pReq.getUser()……
    Please advice, how I we get the hold of group name from orcldefaultprofilegroup (oid)?
    I would really appreciate your reply.
    Thank you.
    - Ali Raza.

    I am not sure about the PDK API to get the group name. But using LDAP API its easy to get the User Group.
    If you find the answer to get the group name using PDK API, Please update in forum. It will really help others.
    --Balaji S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can I retrieve the serial number from my Dreamweaver CS5.5 installation (mac OS X)?

    I don't have access to the serial number any other way.
    Thanks,
    SC

    If you registered your product, you can retrieve your serial number by logging into your Adobe account.
    https://accounts.adobe.com/
    Nancy O.

  • Does anyone know how can I delete the voice messages from my IPhone? The red notification on my phone icon REALLY disturbs me...

    Seriously, the red thingy on top of my icon is annoying me.. And it doesn't let me hear the stupid message

    Contact YOUR OWN carrier (provider/the company you pay for cellular service) and tell them about your problem with listening to your voicemails. They should be able to reset it for you.
    To delete voicemails: Go to voicemail, choose a voicemail, and swipe left. The "delete" option will appear.

  • How can i retrieve the lost bookmarks on my ipad ?

    How can i retrieve the lost bookmarks from my ipad ?

    See if this gets them back.
    Quit Safari completely and reboot the iPad. Go to the home screen first by tapping the home button. Double tap the home button and the recents tray will appear with all of your recent apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus  sign in the upper left corner of the app that you want to close. Tap the home button or anywhere above the task bar.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • How can I retrieve the inbound XML messages (invoices) by ABAP program?

    Where are the inbound XML messages (invoices) saved in XI box?
    How can I retrieve the inbound XML invoices in XI box by ABAP program?
    Is there any method/BADI/function module to retrieve these XML invoices, so I can output these XML invoices in an ABAP report?
    Thanks in advance for your help!

    Hello Fisher,
    This Webblog will help you.
    /people/alessandro.guarneri/blog/2006/02/14/super-message-monitor-for-sap-xi
    From this blog you will understand the code behind SXMB moni .. which performs the selection from database. You can write a report as well.
    Cheers,
    Himadri

  • How can i remove the phone number from the text messages that i receive in the notification center

    how can i remove the phone number from the text messages that i receive in the notification center?

    You choose whether to see text messages in Notification Center or not.  If you elect to see them, they will display the phone number (unless they are from a contact in your contacts list).
    You can choose not to see them at Settings > Notification Center > Messages.

  • How can I retrieve a mail message that was accidentally deleted.  It's not in the trashcan.

    How can I retrieve a mail message that was accidentally deleted.  It's not in the trashcan. 

    Which trashcan, mail or osx

  • How can we retrieve the name of the Parent Space from the subspace?

    We wish to use a hyperlink in a subspace template which allows a user to link back from the subspace to its parent space.
    This hyperlink should show the name of the parent space.
    These Expression Language Expressions return parent information, but they so not show the Name of the parent space or other details like the Parent Space URL.
    #{spaceContext.currentSpace.parent}
    #{spaceContext.space['bpo'].parent}
    How can we retrieve the name of the Parent Space?

    I agree!
    I can't top this approach.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Bookmark 'Open in new Tab' or 'Window' doesn't on this latest install

    Right clicking on a bookmark, allows me to open link in a new tab or window.... this works for the first while, but then breaks down and doesn't open anything. Restarting FF 4.0 works to resolve this issue. But lately after a half hour of working pro

  • JAEHYLEE  (R11i AOL)  Adpatch fails with Pre-req check

    Goal 이미 적용한 patch를 Adpatch가 다시또 Pre-req로 재차 확인을 요청하는 경우가 발생할 경우 Cause adpatch는 AD_SNAPSHOT_BUGFIXES table의 bugfix_id에 record를 가지고 있어여 하나 여기에 데이타가 없는 경우에 prereq check를 잘못할수 있다 fix: adadmin을 사용하여 Maintain snapshot information을 수행을 권고 드립니다. Perform the

  • IDCS2, WIN: Assert error reason

    Hi Guys, I got a assert error, "~InstanceList(): 3 outstanding references to UID 172 (Class kTextStoryBoss).", I don't know the reason, do you guys know that? Thanks,

  • Where is jta.jar?

    Hello all, I am looking to download jta.jar. I went to http://java.sun.com/products/jta/index.html. I was only able to download the class files. Am I looking in the right place? Thanks for the help, Joshua

  • Master-Detail reports in Reports 6i

    I am trying to write a master-detail report where the master record prints on the top of page one and the detail records print on the top of page two. They would repeat this for additional records. Currently I have a repeating frame with two frames i