473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

hello! the problem is always the same but i can't understand why it
happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH
ERROR why?

Dim connessione As New
SqlClient.SqlConnection("Server=SOSQLSRV01;Initial
Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda")
Dim iddestinatario As Integer

Dim TestoQueryCodicecodicedestinario As String = "SELECT
max(id_destinatario) FROM destinatario "
Dim QueryCodicecodicedestinario As New
SqlClient.SqlCommand(TestoQueryCodicecodicedestina rio, Connessione)
Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader
If Connessione.State = ConnectionState.Closed Then
Connessione.Open()
End If
LettoreCodicecodicedestinario =
QueryCodicecodicedestinario.ExecuteReader()
LettoreCodicecodicedestinario.Read()
Dim Codcodicedestinario As String =
LettoreCodicecodicedestinario.GetInt32(0)
LettoreCodicecodicedestinario.Close()
Connessione.Close()
Dim QuerySalvadestinatario As String = "INSERT INTO
Destinatario (Intestazione) VALUES ('ciao')"
Dim Inseriscidestinatario As New
SqlClient.SqlCommand(QuerySalvadestinatario, connessione)
If connessione.State = ConnectionState.Closed Then
connessione.Open()
End If
Inseriscidestinatario.ExecuteNonQuery()
connessione.Close()

Jul 17 '06 #1
3 15324
Rampa,

Be aware that this kind of code can be very problemfull in a multiuser
environment where more users can add rows.

I would use the new Guid as the uniqueidentifier.

As well, as you want to get one value than the command.executescalar is much
better.

http://msdn2.microsoft.com/en-us/lib...utescalar.aspx

And when you want to see what was your error than embed your commands inside
a Try Catch block

Try
result = cmd.executescalar
Catch sqlex as sqlexception
messagebox.show(sqlex.tostring)
Catch ex as exception
messagebox.show(ex.toString
End Try

I hope this helps,

Cor

"Rampa" <on***@libero.itschreef in bericht
news:11**********************@m79g2000cwm.googlegr oups.com...
hello! the problem is always the same but i can't understand why it
happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH
ERROR why?

Dim connessione As New
SqlClient.SqlConnection("Server=SOSQLSRV01;Initial
Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda")
Dim iddestinatario As Integer

Dim TestoQueryCodicecodicedestinario As String = "SELECT
max(id_destinatario) FROM destinatario "
Dim QueryCodicecodicedestinario As New
SqlClient.SqlCommand(TestoQueryCodicecodicedestina rio, Connessione)
Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader
If Connessione.State = ConnectionState.Closed Then
Connessione.Open()
End If
LettoreCodicecodicedestinario =
QueryCodicecodicedestinario.ExecuteReader()
LettoreCodicecodicedestinario.Read()
Dim Codcodicedestinario As String =
LettoreCodicecodicedestinario.GetInt32(0)
LettoreCodicecodicedestinario.Close()
Connessione.Close()
Dim QuerySalvadestinatario As String = "INSERT INTO
Destinatario (Intestazione) VALUES ('ciao')"
Dim Inseriscidestinatario As New
SqlClient.SqlCommand(QuerySalvadestinatario, connessione)
If connessione.State = ConnectionState.Closed Then
connessione.Open()
End If
Inseriscidestinatario.ExecuteNonQuery()
connessione.Close()

Jul 17 '06 #2
Thank you! Really!! I solved the problem!

Be aware that this kind of code can be very problemfull in a multiuser
environment where more users can add rows.

Can you explain me why you say it?

Thank you again!

Cor Ligthert [MVP] ha scritto:
Rampa,

Be aware that this kind of code can be very problemfull in a multiuser
environment where more users can add rows.

I would use the new Guid as the uniqueidentifier.

As well, as you want to get one value than the command.executescalar is much
better.

http://msdn2.microsoft.com/en-us/lib...utescalar.aspx

And when you want to see what was your error than embed your commands inside
a Try Catch block

Try
result = cmd.executescalar
Catch sqlex as sqlexception
messagebox.show(sqlex.tostring)
Catch ex as exception
messagebox.show(ex.toString
End Try

I hope this helps,

Cor

"Rampa" <on***@libero.itschreef in bericht
news:11**********************@m79g2000cwm.googlegr oups.com...
hello! the problem is always the same but i can't understand why it
happens!! Someone can help me? FIRST QUERY GOES WELL, SECOND BREAK WITH
ERROR why?

Dim connessione As New
SqlClient.SqlConnection("Server=SOSQLSRV01;Initial
Catalog=SO_Bolle;Uid=SO_CattolicaRE;PWD=sogeda")
Dim iddestinatario As Integer

Dim TestoQueryCodicecodicedestinario As String = "SELECT
max(id_destinatario) FROM destinatario "
Dim QueryCodicecodicedestinario As New
SqlClient.SqlCommand(TestoQueryCodicecodicedestina rio, Connessione)
Dim LettoreCodicecodicedestinario As SqlClient.SqlDataReader
If Connessione.State = ConnectionState.Closed Then
Connessione.Open()
End If
LettoreCodicecodicedestinario =
QueryCodicecodicedestinario.ExecuteReader()
LettoreCodicecodicedestinario.Read()
Dim Codcodicedestinario As String =
LettoreCodicecodicedestinario.GetInt32(0)
LettoreCodicecodicedestinario.Close()
Connessione.Close()
Dim QuerySalvadestinatario As String = "INSERT INTO
Destinatario (Intestazione) VALUES ('ciao')"
Dim Inseriscidestinatario As New
SqlClient.SqlCommand(QuerySalvadestinatario, connessione)
If connessione.State = ConnectionState.Closed Then
connessione.Open()
End If
Inseriscidestinatario.ExecuteNonQuery()
connessione.Close()
Jul 17 '06 #3
Rampa,
>
Be aware that this kind of code can be very problemfull in a multiuser
environment where more users can add rows.

Can you explain me why you say it?

Thank you again!
Think that both users want to add a row, the both ask for the last and get
that in almost the same time. Than they are both inserting in my idea (id I
did understand your code well), the same id.

Cor
Jul 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
1
by: Adam Smith | last post by:
When executing ExecuteXmlReader() against a table where records are being inserted, I get: 9/5/2003 8:39:47 AM Transaction (Process ID 66) was deadlocked on lock resources with another process...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
2
by: James Cooke | last post by:
Hi all, I want to catch a duplicate key exception. I do not want to provide that verbose message from the MSSQL server - I would put a user friendly message out, like "The item you have added...
7
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. ...
3
by: Jonas | last post by:
Hi! I have a general error logging routine that takes a parameter of type Exception. But if I send in a SqlException, I loose all the Sql-specific information as the variable is casted to an...
2
by: Carol | last post by:
Exception may be thrown in the code inside the try block. I want to handling the SqlException with State == 1 in a special way, and for all others I want to use a general way to handle. Which of...
1
by: Pedro Dinis | last post by:
i have this class library that connects to the database(see appconfig below) compiling 0 errors but when its running i amhaving this error An unhandled exception of type...
2
by: lily86 | last post by:
i'm very new so i hope all of u can help me. when i debug my webforms this error occur "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.