executenonquery - insert works only in debug mode

  • Thread starter Thread starter ADF
  • Start date Start date
A

ADF

I have wrote this code:
-----------------------------------------------------------------------------
Dim cnsql As New SqlClient.SqlConnection

cnsql.ConnectionString = "Data Source=ced2; User ID=sa;
Password=;Initial Catalog=NGN;Persist Security Info=True;"

Dim cmdsql1 As New SqlClient.SqlCommand
Dim i As Integer

Dim j As Integer
cnsql.Open()
cmdsql1.Parameters.Clear()

cmdsql1.CommandText = "insert into MAGAZZINI_SELEZIONATI
(magazzino,utente) values(@magaz,@utente)"

cmdsql1.Connection = cnsql
cmdsql1.Parameters.Add("@Magaz", SqlDbType.NVarChar, 50)
cmdsql1.Parameters.Add("@Utente", SqlDbType.NVarChar, 50)
For i = 0 To Magazzini.Length - 1
cmdsql1.Parameters("@Magaz").Value = Magazzini(i)
cmdsql1.Parameters("@Utente").Value = Me.Utente
cmdsql1.ExecuteNonQuery()
Next i
cnsql.Close()
cmdSql = Nothing
------------------------------------------------------------------------------

Magazzini is an array of strings. If I execute this code in run mode
insert fails and table Magazzini_Selezionati is empty. Code does not
return any error but insert not works. If I execute this code step by
step in debug mode it works right and rows have been inserted into the
table.

Could you tell me why???

I'm working with VS2003, .NET 1.1 SP1 and SQL SERVER 2K SP4.

Thanks in advance

Antonio.
 
Magazzini is an array of strings. If I execute this code in run mode
insert fails and table Magazzini_Selezionati is empty. Code does not
return any error but insert not works. If I execute this code step by
step in debug mode it works right and rows have been inserted into the
table.

Could you tell me why???

I'm working with VS2003, .NET 1.1 SP1 and SQL SERVER 2K SP4.

no matter what the real cause is, in such cases you should always use Sql
Profiler's trace ability to see what query is actually sent to the server.
you will find the Sql Profiler among other tools shipped with SQLServer.

Wiktor Zychla
 
Hi,

Sounds pretty strange. Do you have any exception handling in your code? Are
you testing it in a debug mode and run mode on same PC and against same
server?
 
Back
Top