Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. The sqlcommand is currently busy open, fetching

The sqlcommand is currently busy open, fetching

Scheduled Pinned Locked Moved Visual Basic
helpdatabasesysadminquestionannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eunice VB junior
    wrote on last edited by
    #1

    Hi, I'm trying to create a transaction code within a button click by performing the insert/update/select. Purpose is to make sure every operation can be rollback instead of some table inserted but some not. But I get this error: The SqlCommand is currently busy Open, Fetching. Description: "System.InvalidoperationException. The sqlCommand is currently busy open,Fetching." It happened at "cmd.ExecuteNonQuery()" (the insert command after select command). Line 52 from my codes. Here is my codes. Can anyone help me? Thanks a lot. Dim cn As New SqlClient.SqlConnection cn.ConnectionString = ("server=samtest;uid=sa;pwd=sa;database=Test") Dim cmd As New SqlClient.SqlCommand Dim tn As SqlClient.SqlTransaction Try cmd.Connection = cn If cn.State = ConnectionState.Closed Then cn.Open() tn = cn.BeginTransaction cmd.Transaction = tn j = 0 For j = 0 To jcounter - 1 Dim DefID As Object = dgItem.Item(j, 0) Dim Component As Object = dgItem.Item(j, 1) Dim QtyOut As Object = dgItem.Item(j, 3) Dim FailQty As Object = dgItem.Item(j, 4) Dim Type As Object = dgItem.Item(j, 5) cmd.CommandText = "Insert into LCDTest (UnitID,TestDefID,Component,PassQty,FailQty,Type) values(" & lblUnitID.Text & "," & DefID.ToString() & ",'" & Component.ToString() & "'," & QtyOut.ToString() & "," & FailQty.ToString() & ",'" & Type.ToString() & "')" cmd.ExecuteNonQuery() Next If icounter > 0 Then i = 0 For i = 0 To icounter - 1 Dim DefID As Object = dgResult.Item(i, 0) Dim Component As Object = dgResult.Item(i, 1) Dim FailureCode As Object = dgResult.Item(i, 2) Dim RejQty As Object = dgResult.Item(i, 3) Dim Remark As Object = dgResult.Item(i, 4) cmd.CommandText = "Select ID from LCDTest WHERE UnitID = " & lblUnitID.Text & " and stationid=" & Me.lblStationID.Text & " and TestDefID =" & DefID.ToString() & " " dr = cmd.ExecuteReader() If dr.Read() Then lblTestID.Text = dr(0).ToString() Else MessageBox.Show("No such ID. Please scan again.") lblTestID.Focus() Exit Sub

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups