MSSQL Error: Could not resolve expression for schemabound object or constraint

July 22nd, 2011 3 comments

I’m using Microsoft SQL Server 2005 and the database on which I executed the ALTER VIEW query has compatibility level set to SQL Server 2000(80). The ALTER VIEW query returned this error:

Could not resolve expression for schemabound object or constraint

If you encounter this issue, check the collation of database and collation of MS SQL Server.  In my case server collation was set to SQL_Latin1_General_CP1_CI_AS and database collation Latin1_General_CI_AS.

If you want to find out which columns have specified collation and you do not want to do it manually in SSMS, you can run this script:

SELECT TABLE_NAME, column_name, collation_name
FROM information_schema.COLUMNS
WHERE collation_name = 'SQL_Latin1_General_CP1_CI_AS'

This query will return all columns in all tables/views with specified collation.

If you want to change the collation, following script will generate ALTER statements for you.

WARNING – The script is not absolutely correct, because it will generate ALTER statements for views as well and you cannot alter all types of columns (indexed, used as primary key…). For more details which columns cannot be altered see MSDN ALTER TABLE.

DECLARE @tableName nvarchar(128)
DECLARE @columnName nvarchar(128)
DECLARE @columnType nvarchar(128)
DECLARE @columnLength INT
DECLARE @isNullable VARCHAR(3)

DECLARE @SQL nvarchar(1000)

DECLARE column_cursor CURSOR FOR
SELECT TABLE_NAME, column_name, data_type, character_maximum_length, is_nullable
FROM information_schema.COLUMNS
WHERE collation_name = 'SQL_Latin1_General_CP1_CI_AS'
ORDER BY TABLE_NAME

OPEN column_cursor

FETCH NEXT FROM column_cursor INTO @tableName, @columnName, @columnType, @columnLength, @isNullable

WHILE @@FETCH_STATUS = 0
BEGIN
IF (@isNullable='YES')
BEGIN
SELECT @SQL =( 'ALTER TABLE ' + @tableName + ' ALTER COLUMN ' + @columnName + ' ' + @columnType + '(' + CAST(@columnLength AS nvarchar) + ') COLLATE ' + ' Latin1_General_CI_AS')
END
ELSE
BEGIN
SELECT @SQL =( 'ALTER TABLE ' + @tableName + ' ALTER COLUMN ' + @columnName + ' ' + @columnType + '(' + CAST(@columnLength AS nvarchar) + ') COLLATE ' + ' Latin1_General_CI_AS NOT NULL')
END

PRINT(@SQL)

FETCH NEXT FROM column_cursor INTO @tableName, @columnName, @columnType, @columnLength, @isNullable

END
CLOSE column_cursor
DEALLOCATE column_cursor

GO

The other possibility would be to set COLLATE in ALTER VIEW, but I didn’t try that.

I realize, this is not the best solution, but I needed the quick solution. The better solution would be to change the MS SQL Server collation to same as DB and to recreate whole database with correct collation.

Categories: SQL Tags: , , ,

Spring-data aspects not working in eclipse

July 11th, 2011 2 comments

 

Update: In Eclipse 3.7 Indigo with m2eclipse 1.0.1 everything works fine, all you need to do is to Import existing Maven project.

I saw nice presentation about spring data project at Øredev 2010 conference web page, so I decided to give it a try. I followed the guide from spring data website and everything was working fine, till I tried to create repository (step 8 in guide).

Entity:

@NodeEntity
public class Movie {...}

Repository:

public interface MovieRepository extends GraphRepository {}

After adding this line of code eclipse reported an error:
Bound mismatch: The type Movie is not a valid substitute for the bounded parameter <T extends GraphBacked<?>> of the type GraphRepository<T>.

This means that aspect used on movie entity @NodeEntity was not recognized correctly. So I checked the pom.xml if the aspectj-maven-plugin is configured properly, but everything seemed fine.
After few hours of frustration the solution which worked for me was to remove project from eclipse and run following in console:

mvn eclipse:clean
mvn eclipse:eclipse

Then I imported project (using import “Existing projects into Workspace”) and aspects started to work correctly.

However, there is one catch in this solution. The command mvn eclipse:eclipse generates .classpath file with all dependencies. After import into eclipse, maven dependency management is disabled and if you enable dependency management (Maven -> Enable dependency management), the aspects will stop working again :(


Categories: Java Tags: , , , ,

Finding database passwords with google

July 6th, 2011 No comments

Today I read about how simple google search can reveal your secrets (private pgp key), what reminded me one interesting error which I came across when I was trying to find lunch menu few weeks ago. Instead of lunch menu I got page with “Zend_Db_Statement_Exception Object” with some mysql syntax error. This is not big deal, there is a lot of applications which do not work properly, but then I spotted one interesting section in error log called [_config:protected]. In this section you can find connection string to database with username and password. I notified the administrator of restaurant about the error on the web page (and I was very surprised by their quick and grateful response) and then I tried to google:

"[_config:protected]" zend password

I got 77000 results, pretty much, right? Some of these are questions in forums, others are gone, but there are plenty of error pages working or gone, but still in google cache. I hope that most of these DB servers are not accessible from outside at least. I will probably write(find) some small crawler to get some real numbers and submit this query to google hacking database.

Disclaimer: This post is for meant for educational purposes only. Anyone misusing this information is responsible for his own actions.

Categories: Security Tags: , , ,

Eclipse crash while accessing marketplace

June 12th, 2011 1 comment

I’m using latest archlinux with eclipse 3.6.2 – Helios and openjdk 1.6.0_22. I wanted to manage my eclipse plugins with eclipse marketplace, however each time when I clicked on eclipse marketplace menu, eclipse suddenly crashed. The same thing happened when I navigated to Window-Preferences-General-Web Browser.

To fix the issue you need to add one line into eclipse.ini file (in archlinux located /usr/share/eclipse/eclipse.ini)

-Dorg.eclipse.swt.browser.XULRunnerPath=/usr/bin/

More information can be found here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343454

Categories: Java Tags: , , , , ,