sqlexception

Troubleshooting Timeout SqlExceptions

I have some curious behavior that I'm having trouble figuring out why is occurring. I'm seeing intermittent timeout exceptions. I'm pretty sure it's related to volume because it's not reproducible in our development environment. As a bandaid solution, I tried upping the sql command timeout to sixty seconds, but as I've found, this doe...

Do objects added to the SqlException.Data collection need to be [Serializable]?

Do objects added to the SqlException.Data collection need to be [Serializable]? ...

Finer granularity of SQL Exceptions?

In C# Is there a way of getting a finer granularity with SQL exceptions? I'm aware that an aweful lot can go wrong but I want to deal with certain cases differently and parsing the Error message doesn't seem to be very elegant. Also Are the error messages created by the framework or are they db specific? For example If i have a primar...

Ambiguous column name error

When executing the following (complete) SQL query on Microsoft SQL Server 2000: SELECT B.ARTIFACTTNS, B.ARTIFACTNAME, B.ARTIFACTTYPE, B.INITIALBYTES, B.TIMESTAMP1, B.FILENAME, B.BACKINGCLASS, B.CHARENCODING, B.APPNAME, B.COMPONENTTNS, B.COMPONENTNAME, B.SCAMODULENAME, B.SCACOMPONENTNAME FROM (SELECT DISTINCT A.ARTIFACTTYPE, A.A...

A list of common SqlException numbers?

What are the most common/useful SqlException numbers? I don't need the entire sysmessages table, just the typical or common errors you're likely to see in a data access layer so I can do sometihng like: switch (exception.Number) { case (2): case(53): _error = DataAccessErrorType.NetworkAdd...

C# - What is good SQLException Error Handling for Time-outs and failed connections

I use EntitySpaces for all of my Database related coding. As a sole developer I don't have time to sit and write the SQL for each and every application I write, so using a generator such as ES Suites me down to the ground and saves me days, if not weeks, of time. I generally write a series of helper classes for each of the tables that m...

Why is the Sybase JDBC driver "eating" the exceptions?

I'm using the official Sybase JDBC driver to connect to a database and call a stored procedure by creating a CallableStatement, binding the parameters to it and calling .execute() on it. However, I found that no exception is thrown, even if the stored procedure fails. I can verify that the failure is propagated back to me by sniffing th...

What causes Timeout expired SqlExceptions in LINQ to SQL?

My application keeps running into Timeout Expired SqlExceptions. The thing is that this query is one that will simply have to run for a decent amount of time. I'm having trouble figuring out where this exception is occurring though. Is this a timeout that's created at the database server or is it happening in my program? Or if it cou...

linq to sql insert query not working from unit test project

I'm having a strange behavior in Linq to Sql... I have a simple parent | child (one to many) object model. In my app, I create the parent object and populate the children all in memory, and then call my repository's add method to insert both the parent with its children. Now from my application (winform), all works correctly as expect...

SQLException: JZ0S4: Cannot execute an empty (zero-length) query. on a Prepared Statement

Heres a class executing PreparedStatements on a Connection. public class doSomething { private PreparedStatement ps; public setPS (Connection conn) throws SQLException { String sql = "select * from table where id = ?"; ps = conn.prepareStatement(sql); } public void runSomething(String var){ ps....

SQLiteJDBC and PreparedStatement to use pragma table_info

I'm utilizing Java and SQLiteJDBC to work with SQLite. I need to access name of columns for a given table and I've found that I could accomplish this with the following command: pragma table_info(myTable) However, when attempting to do the following I get an error. PreparedStatement _pstmt = this._DBConnection.prepareStatement("pragm...

How to throw a SqlException(need for mocking)

Hi I am trying to test some exceptions in my project and one of the Exceptions I catch is SQlException. Now It seems that you can't go new SqlException() so I am not sure how I can throw a exception especially without somehow calling the database(and since it is unit tests it is usually advised not to call the database since it is slow...

Recommended approach on handling SqlExceptions in db applications

Hi, I work on a database application written in C# with sql server as backend. And for data integrity, I try to enforce as much as possible on database level - relations, check constraints, triggers. Due to them, if data is not consistent, the save / update / insert can fail, and app throw SqlException. I do various validations both i...

Linq2SQL: "Transaction (Process ID 56) was deadlocked on lock resources with another"

I have a process that (at night) take a large chunk of data in the form of a linq2sql query and dumps this as XML (sitemaps). My problem is that I'm sometimes is getting: System.Data.SqlClient.SqlException: Transaction (Process ID XX) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun...

Outputting the exception from a SQLException error

I have a .aspx page calling a .asmx page's web service. In that .net web service I attempt to open a database connection to SQLServer 2008. The connection is failing. I am not sure why. I am doing this in a try / catch and the catch does get hit when I debug. I'm not sure what I can output there though as I don't have access to the serve...

Login failed for user 'username'

I have a form that selects a bunch of rows from a table in my MSSQL server, now, this form is used to update data, which it does correctly, after I update the data using the form however, it redirects back to a page with a datagrid of all the rows in that table, and allows me to select another row to update, if I select the row I just up...

How do I get SQL LOAD DATA from CSV to honour the column type when loading?

I am loading a CSV file into MySQL (5.1) using CREATE TABLE and LOAD DATA. I have a number of columns which are textual types (categories) but contain numerical values. When I create the table I assign these columns as VARCHAR(254) but the JDBC driver throws a SQLException "Data truncated for column AgeGroup at row 1". My data looks l...

SQLException in JDBC

Hi, I am getting a SQLException when I try to run the query in Informix DB using JDBC. The query is huge in size: select * table_name where tableid in (....) I get an exception because the 'in' part contain more than 5000 values and because of the length. Is there a way to avoid this or should I break it down and run two queries? ...

Why does a SqlException thrown by SqlCommand.ExecuteNonQuery contain all the PRINTs as errors?

Hello! When I run the following snippet try { using (SqlConnection conn = new SqlConnection("I'm shy")) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "PRINT 'A';PRINT 'B';PRINT 'C';RAISERROR('SQL_Error', 18, 1)"; cmd.ExecuteNonQuery(); } } } catch (SqlException ex) { MessageBox.Show...

SQL Exception Data

I have written a program which uses a SQL exception class and then use it show custom messages for the primary key violation. Also i want the primary key value that caused the violation. How can i get all the primary keys which generated the exception from the sqlexception object. Catch se As SqlException For i As Integer...