executenonquery - insert works only in debug mode

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.
 
W

Wiktor Zychla [MVP]

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
 
V

Val Mazur \(MVP\)

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top