Page 1 of 1

Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 8:00 am
by zoggler
Hello,

I try to import a table from a MSSQL Server, but i get always the error "Primary key property is empty".
I was trying to move my db table to the default schema of the MSSQL "DBO" and than the import is functioning.

I test with the actual version "QxEntityEditor 1.1.6 - Windows 64 bits (portable)"

Regards zoggler

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 8:34 am
by qxorm
Hello,

1- In the "Import from database using ODBC" screen, have you selected the database type (by default this is "Generic", but in your case you have to put "MS SQL Server") ?
2- Maybe your table doesn't have any defined primary key (QxEntityEditor cannot manage entities without primary key) ?

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 8:48 am
by zoggler
Hello ,

I use the "MS SQL Server" setting and I have a primary key defined.
Here is a SQL script of a table in my db.

Regards

Code: Select all
CREATE TABLE [icore].[usergroup](
   [usergroup_id] [int] IDENTITY(1,1) NOT NULL,
   [version] [int] NULL,
   [ownercorporation_id] [int] NULL,
   [ownerplant_id] [int] NULL,
   [deleted] [tinyint] NULL,
   [creationdate] [datetime] NULL,
   [name] [varchar](50) NOT NULL,
   [ownerbusinessunit_id] [int] NULL,
PRIMARY KEY CLUSTERED
(
   [usergroup_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED
(
   [usergroup_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 9:14 am
by qxorm
Ok, I can reproduce your issue with your table script.
Here is the way how QxEntityEditor get all information from a MS SQL Server database :

1- To get all tables/views :
Code: Select all
SELECT
  table_name,
  table_schema,
  table_type
FROM
  information_schema.tables
WHERE
  (table_type = 'BASE TABLE' OR table_type = 'VIEW');


2- To get the primary key of a specific table :
Code: Select all
SELECT
  column_name
FROM
  information_schema.key_column_usage
WHERE
  OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1 AND
  table_schema = 'icore' AND
  table_name = 'usergroup';


The query to get the primary key returns empty : that means that this condition doesn't work : OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey')

Do you have any idea why this condition doesn't work ?
Do you have a better query to get the primary key of a table ?

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 10:14 am
by zoggler
The problem is the function "OBJECT_ID" ! You have to add the constraint_schema information.
Here is a sample.
Is it possible to get a new version of the plugin?

Regards

Code: Select all
OBJECT_ID ( '[ database_name . [ schema_name ] . | schema_name . ] object_name' [ ,'object_type' ] )

SELECT  column_name
FROM
  information_schema.key_column_usage
WHERE
  OBJECTPROPERTY(OBJECT_ID(constraint_catalog+'.'+constraint_schema+'.'+constraint_name), 'IsPrimaryKey') = 1 AND
  table_schema = 'icore' AND
  table_name = 'usergroup';

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 10:51 am
by qxorm
Thank you for your fix !
You can download the plugin (for QxEntityEditor 64bits on Windows) with your fix here : http://www.qxorm.com/temp/QxEEOdbcImport.zip

Please let me know if it is working fine now with this new plugin...

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 11:08 am
by zoggler
It's functioning now, thanks!

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 11:18 am
by qxorm
It's functioning now, thanks!

Great !

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 11:33 am
by zoggler
Hi ,
a other question.

I want to buy a version of the editor. Now my questions:
1. I also get the source code
2. Do I have to buy a license from the QxOrm to start a commercial project or the licence is includet in the editor fees

Regards

Re: Error Import from MSSQL (Primary key property is empty)

PostPosted: Tue Aug 26, 2014 12:23 pm
by qxorm
Hi,
To purchase a QxOrm QXPL license and a QxEntityEditor license key, please contact us at this e-mail : contact@qxorm.com