RE: Implicit conversion from data type text to nvarchar is not allowed.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello Bo,

This is a known issue when using the SQL Server 2005 JDBC Driver to access
SQL Server 2000. The following section from the release.txt file applies:

========================================================================
3) SQL SERVER 2000 DATA CONVERSION LIMITATIONS

When using SQL Server 2000 with the JDBC driver, the following data
conversion limitations apply:

- String data cannot be converted to an underlying money or
smallmoney column.
- String data longer than 4000 characters cannot be converted
to char or varchar underlying columns.
- String data more than 4000 characters cannot be converted to nchar or
nvarchar underlying columns if the sendStringParametersAsUnicode
connection string property is set to false, or the setAsciiStream
method is called.
- String data cannot be converted to text columns if the
sendStringParametersAsUnicode connection string property is set
to true. If you need to support string to text columns conversions,
set the sendStringParametersAsUnicode property to false.
========================================================================

The following test on my system is resolved by setting
sendStringParametersAsUnicode to false:

Connection conn = null;
conn = DriverManager.getConnection(connStr);
if (null == conn) {
System.out.println("Unable to establish connection.");
return;
}
PreparedStatement ps = conn.prepareStatement("INSERT INTO StringInput
VALUES (?)");
String myString = "The quick brown fox jumps over the lazy dog.";

ps.setAsciiStream(1, new ByteArrayInputStream(myString.getBytes()),
myString.length());
int updateCount = ps.executeUpdate();
ps.close();
conn.close();

Incidentally, I am not familiar with any indexing issues that arise from
the use of setString() that would be alleviated by using setAsciiStream().
Both methods actually appear the same when viewed from the server:

declare @P1 int
set @P1=1
exec sp_prepexec @P1 output, N'@P0 varchar(8000)', N'INSERT INTO
StringInput VALUES (@P0) ', 'The quick brown fox jumps over the lazy
dog.'
select @P1

Best regards,
Matt
--
Matt Weber [MSFT]
Microsoft Developer Support - SQL Developer

This posting is provided "AS IS", with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for
newsgroup purposes only.

.



Relevant Pages

  • Re: Implicit conversion from data type text to nvarchar is not allowed.
    ... The data conversion known issue you mentioned doesn't seem to apply in this case because I am converting String data less than 4000 characters to varchar column with setAsciiStream. ... This is a known issue when using the SQL Server 2005 JDBC Driver to access SQL Server 2000. ... connection string property is set to false, ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Implicit conversion from data type text to nvarchar is not allowed.
    ... I agree that the data conversion issue should not apply to your scenario, ... this case because I am converting String data less than 4000 characters to ... This is a known issue when using the SQL Server 2005 JDBC Driver to ... connection string property is set to false, ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Unexpected results
    ... The WITH statement should remove the data that cannot be converted to int ... There is a query hint that as the name implies forces SQL Server to execute joins in the order they are listed, but this is a last-resort performance hack and not meant to fix general issues like this. ... a change in your data means the execution plan or its actual execution may have changed so SQL Server hits on offending records it never considered before. ... SET ANSI_WARNINGS OFF also heads off conversion errors, but it has undesired consequences and the way ANSI_WARNINGS, ARITHABORT and ARITHIGNORE interact is headache-inducing. ...
    (microsoft.public.sqlserver.programming)
  • RE: SSMA - Query Conversion to Stored Procedures.
    ... you also want to migrate those queries with parameters into SQL Server ... However you found that none of your Access parameter queries are converted ... to stored procedures and that an undefined error came out. ... from the conversion objects list we can see that Access queries can ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Conversion error
    ... concatenate ahours, aminutes, aseconds, amillisecons into one column. ... Conversion failed when converting the varchar value ':' to data type ... SQL Server has a strict type precedence, ...
    (microsoft.public.sqlserver.server)