Start a new topic


I am trying to make a SQL call from the IOM API and I am having issues connecting to the DB.



            Using sqlcmd As SqlClient.SqlCommand = Import.SqlConnection.CreateCommand()

                sqlcmd.CommandText = String.Format(sqlbase, Import.Fields.GetByIndex(0).Value)

                fromConsID = CInt(sqlcmd.ExecuteScalar())

                sqlcmd.CommandText = String.Format(sqlbase, Import.Fields.GetByIndex(1).Value)

                toConsID = CInt(sqlcmd.ExecuteScalar())

            End Using

Source row 1 produced Excel error row 2: Error in custom code AfterDictionaries: ExecuteScalar requires an open and available Connection. The connection's current state is closed. Line:0 [CImport_Process_02.6]

what am I missing here?

1 Comment


Import.SqlConnection returns a new connection each time. Store it in a variable and use the variable to create your command.
Login or Signup to post a comment