SQL Server 2005 and Datanucleus problem (ntext query) - sql-server

Started getting errors with SQL Server 2005
This is the first time i've tested our app with Datanucleus 2.x (last test was made with DN 1.x)
I use Eclipse RCP.
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The ntext data type cannot be selected as DISTINCT because it is not comparable.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPrepared
Statement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java
:283)
at org.datanucleus.store.rdbms.SQLController.executeStatementQuery(SQLController.java:463)
at org.datanucleus.store.rdbms.query.JDOQLQuery.performExecuteInternal(JDOQLQuery.java:755)
... 5 more

As the first line mentions, you are trying to do a DISTINCT on a result set that has ntext type fields inside it .. this is not possible..
have a look at Is there any way to DISTINCT or group by a text (or ntext) in SQL Server 2005? for possible solution. (cast the field to nvarchar(max))

Related

MS Access: How to specify a ODBC Connection String with country specific date queries?

I have severe troubles to set up an MS access application that uses linked tables to an SQL Server 2012 Database.
The problem is that SQL Queries have problems to interpret German dates: e.g. "31.12.2019" doesn't work, "01.01.2019" works. So I suspect that it is a problem with localization. E.g.
select * from table where date >= [Forms]![someForm]![fromDate]
[Forms]![someForm]![fromDate] is a string in a form, edited by a date picker.
I was able to solve the problem by using the ODBC Microsoft SQL Server Setup Wizzard, and selecting "Ländereinstellungen verwenden" (engl. use country specific settings).
(Sorry the following screenshot is in German).
I would like to specify this in a classic ODBC connection string: e.g
DRIVER=ODBC Driver 13 for SQL Server;SERVER=.\SqlExpress2012;Trusted_Connection=Yes;APP=Microsoft Office;DATABASE=suplattform;?country-specific=yes?
However I did not find such an parameter in any documentation. Is this possible?
Best regards
Michael
Also, specify the data type of the parameter - and date is a reserved word in Access SQL:
parameters [Forms]![someForm]![fromDate] DateTime;
select * from table where [date] >= [Forms]![someForm]![fromDate]

SQL Server 2016 - Invalid object name 'hibernate_sequence'

I have an image backup that I restore to the MS SQL server 2016.
I have an entity that declares its id like that:
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#XmlID
#XmlElement
#XmlJavaTypeAdapter(IntToStringXmlAdapter.class)
private Integer id;
when I save the entity I receive:
Hibernate: select next_val as id_val from hibernate_sequence with (updlock, rowlock) 2018-02-28 22:05:41.935
ERROR 18152 --- [nio-8080-exec-6] o.hibernate.id.enhanced.TableStructure : could not read a hi value com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'hibernate_sequence'.
......
2018-02-28 22:05:41.942 WARN 18152 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 208, SQLState: S0002
2018-02-28 22:05:41.942 ERROR 18152 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : Invalid object name 'hibernate_sequence'.
I have created by hand the sequence to the SQL server and I make sure that it exist through the SSMS.
CREATE SEQUENCE hibernate_sequence
AS INTEGER
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 99
NO CYCLE;
Despite of this I continue to the receive the previous error.
Any ideas what I am doing wrong?
Thank you in advance
Following points to check:
What dialect you are using?
What hibernate version you are using?
Version 5 changed the GenerationType.AUTO behavior
Set "hibernate.hbm2ddl.auto" to update and see what it creates in the database
Avoid GenerationType.AUTO. Set it explicit to GenerationType.IDENTITY or GenerationType.SEQUENCE depending on what you want or your DB supports.
Check if you have the latest SQL Server JDBC driver. I had issues with it migrating from hibertnate 4.3 to 5.0
In hibernate 5 set hibernate.id.new_generator_mappings to false
It seems you are upgrading SqlServer version. I faced it when i was upgrading SqlServer 2012 to SqlSever 2017.
Caused by : talk between driver (jtds or sqlserver ) and SqlServer 2017+ no more consider table "dbo.hibernate_sequence" as work-around. It needs specifically sequence with name hibernate_sequence.
solution : delete table named as dbo.hibernate_sequence and create sequence
Example :
USE [your_database_name]
GO
CREATE SEQUENCE [dbo].[hibernate_sequence]
AS [bigint]
START WITH 10000000
INCREMENT BY 1
MINVALUE -9223372036854775808
MAXVALUE 9223372036854775807
CACHE
GO
SqlServer Studio screenshot
You really need to look at the documentation for this. The query you have here is totally wrong. And why are you trying to use query hints on a sequence?
The correct syntax would look this.
select next value FOR hibernate_sequence as next_val
Here is the documentation on this. https://learn.microsoft.com/en-us/sql/t-sql/functions/next-value-for-transact-sql
I was also getting the same error in spring boot project.
In my case the error com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'sys.sequences' is showing because I was using sql server 2008 version which doesn't have sys.sequences object.
I switched to sql server 2017 and it is working fine.
I had this problem and in my case i had to change the dialect from SQLServerDialect to SQLServer2012Dialect. The first has no implementation for sequences.

How do I avoid date type column of MSSQL INTO PIVOTAL HAWQ null at DBMS migration

We are trying to pull data from external source (mssql) to postgres. But when i checked for invoicedate column entries are getting blank at the same time mssql is showing invoicedate values for those entries.
ie
We tried following query on both the DBMS:
When query executed in SQL Server:
select * from tablename where salesorder='168490'
getting 12 rows where invoicedate column is '2015-10-26 00:00:00.000'
But same query is executed on Postgres
select "InvoceDt" from tablename where salesorder='168490'
Getting 12 rows where the column invoicedate is null.
Question is why?
Postgres InvoiceDt column is coming null rather than we can see that SQL Server is showing appropriate data values.
Why is the data different between SQL Server and Postgres for this particular column?
Vicps, you aren't using Postgres and that is why a_horse_with_no_name is having such a hard time trying to understand your question. You are using Pivotal HDB (formally called HAWQ). HAWQ is now associated with the incubator project, "Apache HAWQ" and the commercial version is "Pivotal HDB".
Pivotal HDB is a fork of Pivotal Greenplum database which is a fork of PostgreSQL 8.2. It has many similarities to Postgres but it is most definitely not Postgres.
You are also using Spring-XD to move the data from SQL Server to HDFS which is critical in understanding what the true problem is.
You provided this example:
CREATE TABLE tablename ( "InvoiceDt" timestamp )
LOCATION ('pxf://hostname/path/to/hdfs/?profile=HdfsTextSimple')
FORMAT 'csv' ( delimiter '^' null 'null' quote '~');
Your file only has one column in it? How is this possible? Above, you mention the salesorder column. Secondly, have you tried looking at the file written by Spring-XD?
hdfs dfs -cat hdfs://hostname:8020/path/to/hdfs | grep 168490
I bet you have an extra delimiter, null character, or an escape character in the data which is causing the problem. You also may want to tag your question with spring-xd too.

How do I convert an Oracle TIMESTAMP data type to SQL Server DATETIME2 data type while connected via Link Server.?

I have tried some examples but so far not working.
I have a Link Server (SQL Server 2014) to an Oracle 12C Database.
The table contain a datatype TIMESTAMP with data like this:
22-MAR-15 04.18.24.144789000 PM
When attempting to query this table in SQL Server 2014 via link server I get the following error using this code:
SELECT CAST(OracleTimeStampColumn AS DATETIME2(7)) FROM linkServerTable
Error:
Msg 7354, Level 16, State 1, Line 8
The OLE DB provider "OraOLEDB.Oracle" for linked server "MyLinkServer" supplied invalid metadata for column "MyDateColumn". The data type is not supported.
While the error is self explanatory, I am not certain how to resolve this.
I need to convert the timestamp to datetime2. Is this possible?
You can work around this problem by using OPENQUERY. For me, connecting to Oracle 12 from SQL 2008 over a linked server, this query fails:
SELECT TOP 10 TimestampField
FROM ORACLE..Schema.TableName
...with this error:
The OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" supplied invalid metadata for column "TimestampField". The data type is not supported.
This occurs even if I do not include the offending column (which is of type TIMESTAMP(6). Explicitly casting it to DATETIME does not help either.
However, this works:
SELECT * FROM OPENQUERY(ORACLE, 'SELECT "TimestampField" FROM SchemaName.TableName WHERE ROWNUM <= 10')
...and the data returned flows nicely into a DATETIME2() field.
One way to solve the problem is to create a view in oracle server and convert the OracleTimeStampColumn compatible with sql server's datetime2datatype. You can change the time format to 24 hours format in oracle server's view and mark the field as varchar. Then you can convert the varchar2 column to datetime2 when selecting the column in SQL Server.
In Oracle Server
Create or Replace View VW_YourTableName As
select to_char(OracleTimeStampColumn , 'DD/MM/YYYY HH24:MI:SS.FF') OracleTimeStampColumn from YourTableName
In SQL Server
SELECT CAST(OracleTimeStampColumn AS DATETIME2(7)) FROM **linkServerVIEW**

combining sql server spatial and NHibernate with CreateSqlQuery

I have not mapped geography table in sql server 2008, and I want to query it with a polygon instance in c# using nhibernate.
In the beggining I was trying to use sql server spatial directly but encountered this problem:
Using SQL Server 2008 Geography types with nHibernate's CreateSQLQuery
My second try was this:
session.CreateSQLQuery("select [shape] from [table] where (:codeShape).STIntersects([shape]) = 1").SetParameter("codeShape", codeShape, NHibernateUtil.Custom(typeof(MsSql2008GeographyType)));
however this try also raise an exception:
Could not execute query [select [shape] from [table] where (?).STIntersects([shape]) = 1")] Name:codeShape - Value:POLYGON((30 40, ...))
and the inner exception is:
The specified input does not represent a valid geography instance.
That's despite codeShape.IsValid returns true.
When I run this query directly in sql server I get the expected result.
any ideas or solutions?
Thanks.
problem resolved. I had to reverse the points of the polygon.

Resources