You must Sign In to post a response.
  • Category: Windows 8

    Executenonquery is returning -1 for the query which is running correctly in sql/db2 editor

    I am trying to insert record for parent and child id in one transaction. When I am running my application all records for parent id are inserting correctly but for child id after some records insertion Command.Executenonquery() is returning -1.

    I have given command.timeout value still it is not working.

    When I am running that same insert query in db2 editor,that is executing successfully. Also I am not able to catch the exception why query fails.

    Code is return in VB.Net and database is db2.

    Please advise. Thanks!
  • #768357
    Hi,

    How the execution process is happening in your application. Like first you are inserting parent and then child?
    How was the constraints are created between two tables?

    While inserting the data's have you checked all the input parameters which are passing. Kindly keep the debug point during the child table insertion and get all the parameters from the application and try to execute the script with the input parameter we got.

    Because there is possibility like addition space like "char" and "char " which we cant recognize in the front end.
    So kindly check those possibilities.

    Thanks,
    Mani

  • #768361
    Have you put TRY...CATCH for your insert statement, try to check what is the issue, if the executeNonQuery return -1 after successfully then there exist some issue, in may cases it is found that if the firewall block some database activity then also it returns -1
    so try to disable your Antivirus and firewall from database server and execute the request

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #768363
    first of all my trnsaction starts and then I am inserting all listview record for Parent key as well as Child key using for loop.
    I am inserting these records in same table in single transaction. So if there are 2000 records in listview, I am inserting those 2000 record for parent key and that same record for child key.

    I can see that application inserting all records correctly for parent key for all time but not for child key. When application hangs Executenonquery returns -1 for child key.

    Sometime application insert records correctly for both parent as well as child key.

  • #768364
    Try catch block exist in code but as executeNonQuery retuning -1 and not any exception I suspect that something is not working at database end it might be due to timeout or deadlock.

  • #768368
    Hi,
    Try to use transaction logging of SQL to check what is happening at database end . After each database transaction, a log record is written to the transaction log.

    Enable it using following command:

    DBCC SQLPREF


    Backup it to disk using following command:

    BACKUP LOG DBNAME
    TO DISK = 'D:\DBNAME.TRN'
    GO


    Please refer more details about SQL Transaction logging over here:
    http://www.sqlshack.com/beginners-guide-sql-server-transaction-logs/


Sign In to post your comments