Questions tagged [sqlexception]

An exception that is thrown when the database driver encounters an error. This tag could be used for both C# `SqlExpection` and Java `SQLException`.

C#

SqlException is thrown when encounters a SQL Server related error.

SqlException is the class used by System.Data.SqlClient library to represent an error either communicating with, or generated by, SQL Server.

For errors that are generated by the SQL Server, the Number property will contain SQL Server's error number and Class contains the severity. If there was more than one error or warning returned by the server, then the details of the exception will be populated by the first error\warning and any other errors and warnings can be viewed in the Errors property.

For communication errors, the Message will contain the error details from the network provider and, with .Net 4.5 and above, the InnerException will contain the relevant Win32Exception.

For more information onSqlException, see its MSDN page

Java

An exception that provides information on a database access error or other errors, could be thrown by driver. See official javadoc for more details.

875 questions
319
votes
15 answers

When does SQLiteOpenHelper onCreate() / onUpgrade() run?

I have created my tables in my SQLiteOpenHelper onCreate() but receive SQLiteException: no such table or SQLiteException: no such column errors. Why? NOTE: (This is the amalgamated summary of tens of similar questions every week. Attempting to…
laalto
  • 150,114
  • 66
  • 286
  • 303
121
votes
11 answers

java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F...'

I have the following string value: "walmart obama " I am using MySQL and Java. I am getting the following exception: `java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F...' Here is the variable I am trying to insert into: var1…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
119
votes
18 answers

Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0

I have an Insert stored procedure which will feed data to Table1 and get the Column1 value from Table1 and call the second stored procedure which will feed the Table2. But when I call The second stored procedure as: Exec USPStoredProcName I get the…
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
110
votes
16 answers

How to throw a SqlException when needed for mocking and unit testing?

I am trying to test some exceptions in my project and one of the Exceptions I catch is SQlException. It seems that you can't go new SqlException() so I am not sure how I can throw an exception especially without somehow calling the database (and…
chobo2
  • 83,322
  • 195
  • 530
  • 832
103
votes
3 answers

How to catch SqlException caused by deadlock?

From a .NET 3.5 / C# app, I would like to catch SqlException but only if it is caused by deadlocks on a SQL Server 2008 instance. Typical error message is Transaction (Process ID 58) was deadlocked on lock resources with another process and has…
Joannes Vermorel
  • 8,976
  • 12
  • 64
  • 104
72
votes
9 answers

How to catch a specific SqlException error?

Q: Is there a better way to handle SqlExceptions? The below examples rely on interpreting the text in the message. Eg1: I have an existing try catch to handle if a table does not exist. Ignore the fact that I could check if the table exists in…
Valamas
  • 24,169
  • 25
  • 107
  • 177
64
votes
6 answers

java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver

I'm getting this exception when I try to run this program. It's one of the Microsoft examples. I've added the sqljdbc4.jar to the classpath in netbeans for both compile and Run, via the project properties. I also tested that the class could be found…
Larry Watanabe
  • 10,126
  • 9
  • 43
  • 46
38
votes
9 answers

Catch duplicate entry Exception

How can i catch this Exception : com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '22-85' for key 'ID_CONTACT'
Hayi
  • 6,972
  • 26
  • 80
  • 139
33
votes
8 answers

conversion of a varchar data type to a datetime data type resulted in an out-of-range value

I have the following piece of inline SQL that I run from a C# windows service: UPDATE table_name SET status_cd = '2', sdate = CAST('03/28/2011 18:03:40' AS DATETIME), bat_id = '33acff9b-e2b4-410e-baaf-417656e3c255', cnt = 1, …
amateur
  • 43,371
  • 65
  • 192
  • 320
32
votes
3 answers

Dapper dynamic parameters throw a SQLException "must define scalar variable" when not using anonymous objects

(This code is using Dapper Dot Net in C#) This code works: var command = "UPDATE account SET priority_id = @Priority WHERE name = @Name"; connection_.Execute(command, new { Name = "myname", Priority = 10 } ); This code throws a SqlException: class…
sh-beta
  • 3,809
  • 7
  • 27
  • 32
24
votes
2 answers

How to get parameters from PreparedStatement?

I'm writing generic logger for SQLException and I'd like to get parameters that were passed into PreparedStatement, how to do it ? I was able to get the count of them. ParameterMetaData metaData = query.getParameterMetaData(); parameterCount =…
IAdapter
  • 62,595
  • 73
  • 179
  • 242
20
votes
3 answers

Java java.sql.SQLException: Invalid column index on preparing statement

my code below query the database for a set of rows based on user input. I have tried and tested the query inside of SQL Developer and it works perfectly fine returning the correct rows. And example of an input is : 2013-01-22 But for some reason…
user1851487
  • 547
  • 5
  • 13
  • 28
18
votes
2 answers

SQL Server, C#: Timeout exception on Transaction Rollback

I've got a strange problem. I have a .NET program and my process logic needs a long-running transaction (~20min) on a SQL Server 2005 database. That's ok, since nobody accesses the database in parallel. When something goes wrong, the transaction…
Matthias
  • 3,403
  • 8
  • 37
  • 50
17
votes
3 answers

Get the metadata for prepared statement in java with MySql DB

I want to fetch parameter name and parameter type of given prepared statement. I am using MySQL Database. But when I run my program it is throwing an error: Exception in thread "main" java.sql.SQLException: Parameter metadata not available for the …
user591790
  • 545
  • 2
  • 15
  • 33
17
votes
1 answer

Dapper and In Condition

Using Dapper, the following throws Incorrect syntax near ','. const string sql = "select * from ZipToZipDistance z where z.NoRouteFound = 0" + " and z.OriginZip in (@zips) or z.DestZip in (@zips)"; var zipStrings = zips.Select(x =>…
Tim Scott
  • 15,106
  • 9
  • 65
  • 79
1
2 3
58 59