ogr2ogr to import GML with spatial and non-in SQL Server - sql-server

I am trying to use ogr2ogr to import GML file into SQL Server Spatial. I successfully import features with geometry, but I have few without geometry column. How can I import all of them?
EDIT:
I reinstalled GDAL, installed latest, works fine, but again cann't write non-spatial features.
Constantly getting error:
ERROR 1: Error creating layer: [Microsoft][ODBC SQL Server Driver][SQL
Server]Incorrect syntax near 'NULLCONSTRAINT'.

The error looks like incorrectly formed SQL statement, created by ogr2ogr against the SQL database.
Have you tried running SQL Server Profiler (within SQL Server) whilst you do the import? Assuming you run a standard trace, you will need to locate the row with NULLCONSTRAINT in the textData column in the trace output. Once you have found the problem statement, this should give you some idea how to fix the problem.
If you need a very simple tutorial on the Profiler this link might help
http://www.mssqltips.com/sqlservertutorial/272/profiler-and-server-side-traces/
A similar error for me was caused by square brackets in the shapefile name I was importing which meant the create table statement was invalid.

Related

Cannot run JSON_VALUE in SQLite database (.db file) in SQL Server Management Studio

I want to update some JSON data in SQLite database (.db file) and I met a problem.
I work in Microsoft SQL Server Management Studio where I added SQLite/SQL Server Compact Toolbox through Visual Studio Extensions. I'm succesfully able to connect to this file and I'm also able to run a query on this database (create table, insert data etc.). The only problem is that a table I want to update has a JSON column and I need to use the JSON_VALUE function to get some data from that column. And when I run SELECT JSON_VALUE([data]) FROM myTable, I get an error message:
ErrorCode : 1
Message : SQL logic error
no such function: json_value
Result : Error
for a query SELECT sqlite_version I got a result 3.24.0.
What am I doing wrong? What should I add to system to make this thing working? In standard SQL everything is working fine. SSMS is version 14.0.
I also tried programs "DB Browser for SQLite" and "SQLiteStudio" and also did the same example in Visual Studio and got exactly the same error.
Any hints (please step by step, I'm totally new to SQLite) would be appreciated.

Query with SQL Server 2008 R2 with FireDAC

I'm new to Firedac but not with Delphi
I can make a connection with SQL Server, and when I connect, there is no problem. I get connection OK. It works with code, with the wizard and with the FireDAC explorer.
The name of the database is :
C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\3410b539-431f-4dff-ad0d-a574d1b13498.MDF
I'm stuck with a simple query.
SELECT *
FROM Account;
This query works from within the FireDac explorer but not from my program, I'm getting the following error:
[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Could not find server 'C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\MSSQL' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.'
I'm also also getting the same error, when I try to do it from the UI within Delphi.
To try the query, I dropped onto the form a TFDQuery, the connection property was set automatically to the unique connection on the form. Then I set the query with the query editor, I get the error when I click on execute.
With code it like this :
FDConnection1.Connected := true;
FDQuery1.Close;
FDQuery1.SQL.Text := 'select * from Account;';
FDQuery1.Active := True;
When I debug the program, I get the error when setting the query active.
I see that the name of the DB is not complete in the error message. But it's complete in the component settings
Please advise,
I tried some extra test :
If I run the query from the UI editor (double-clicking on the FDConnection, Tab SQL Script), type the query, it works :-).
But when I try to do it on the FDQuery component, with the connection assigned to previous FDConnection, I get the same error. It' like some parameters are missing.
You are using the location of the SQL data file, instead of the name of the SQL Database.
If you do not know the name you can use the wizard to try and find it.
(Sorry could not add comments yet. This is also mentioned by Jens in the comments)
Update: if that is really the name, try enclosing it in [ ].
I got this response from an Embarcadero engineer:
The problem is not in FireDAC, but in SQL Server ODBC driver
SQLPrimaryKeys function. It fails to work with a catalog name
containing a dot. FireDAC uses this function to get primary key fields
for a result set, when fiMeta is included into FetchOptions.Items. So,
as a workaround / solution, please exclude fiMeta from
FetchOptions.Items.

Pdo mssql error messages

I'm using pdo through freetds driver to connect to Mssql database and I'd like to output detailed sql errors against the generic one.
E.g. I got this generic error from PDO
SQLSTATE[HY000]: General error: 547 General SQL Server error: Check messages from the SQL Server [547] (severity 16) [(null)]
But SQL client gives me more details, and I'd like to get them in php. E.g. in the same case:
The DELETE statement conflicted with the REFERENCE constraint "FKORDINICLIENTI". The conflict occurred in database "dbo.Ordini", column 'IDCliente' of database "dbName".
I've already read this old note PHP / PDO / MSSQL how to get error informations?
and I'd prefer to avoid an additional query.
Thanks.
I think code doesn't matter, I know what's wrong in sql, just wanted to access the second code block from php.
I solved using odbc driver instead of freetds.

SQL Server 2012 error: object reference not set to an instance of an object

I use SQL Server 2012 and I have some databases on it. The problem is I suddenly get an error saying,
object reference not set to an instance of an object
I get this error when:
Going to write a new query
Select previously entered data by right click the table name ->
Select top 1000 rows
What I can do without getting error message:
Log into my instance successfully using both Windows Authentication mode and SQL Authentication mode.
Edit the table data by right click the table name -> Edit top 200 rows
Create a new database
I'm using:
Microsoft SQL Server Management Studio: 11.0.3128.0
Microsoft .NET Framework: 4.0.30319.34014
Operating System: Windows 8.1
Here are some snapshots of the error.
Please give me a solution to fix this problem. Your help will be highly appreciated.
I fixed the problem by running SSMS as administrator.
I could solve the error.
Repair the SQL Server.
Go to Add/remove programs Microsoft SQL Server 2012(x64) -> Uninstall/Change -> Repair.
Select the instance that you want to repair here.
For me, after repairing the instance, the error was solved.
Thanks for all who spent their valuable time to reply my question.
I got the same error message. Problem was 0 bytes free on the C: drive.
Its may be late, but i get the same error in SQL SERVER 2016, i resolved it by assigning full access to the back up folder.
I faced the same error once in my project. This is purely due to SSMS(sql client) is corrupted. Just for cross check that server is fine and client is corrupted, try to connect to the sql-server in this machine from any other server if you have access and query the tables. If it returns data, just uninstall and reinstall the client(ssms) to solve the issue
Thanks
I got the same error for SQL 2016 and the only solution for me was to completely uninstall (in appwiz.cpl) all entries Visual Studio + SQL. Then I executed VisualStudioUninstaller and I reinstalled SQL and after Visual Studio.
I got the same message when I try to alter table to add new column . Issue is I haven't enclosed data types using '[' datatype ']' . Its Real data type. But It got fixed when I enclosed in using square braces.
My solution for this was to extract the csv file with the python library pandas rather than saving it with Excel. Further, I removed columns that I didn't need as a few columns caused formatting errors during the import.
For those who are unable to modify their SQL configuration due to administrative restrictions at work:
I was able to open a new query page by creating a SQL Server Scripts project and adding a new query through the solution explorer
I got the message after deleting a database. The database was gone, so I moved on.

Sqoop export from hdfs to SQL Server 2005 using jdts driver fails

I'm trying to export data from hdfs text file to SQL Server using sqoop. When I have more than a couple of rows to insert it throws the following exception:
java.io.IOException: java.sql.SQLException: Incorrect syntax near ','.
at org.apache.sqoop.mapreduce.AsyncSqlRecordWriter.close(AsyncSqlRecordWriter.java:192)
at org.apache.hadoop.mapred.MapTask$NewDirectOutputCollector.close(MapTask.java:567)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:675)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.sql.SQLException: Incorrect syntax near ','.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResul
I've checked the data for inconsistencies and i can't find anything strange.
I was wondering is the driver even supported?
The problem was being caused with the default way sqoop/jtds group multiple insert statements into 1 using comma separated list of values. This approach is not compatible with sqlserver 2005. To get around it I enabled jdbc-batch insert by providing --batch parameter.
The default way sqoop/jtds group multiple insert statements into 1 is supported with sqlserver 2008.
Also, when I tried the same thing (without the --batch argument) using ms-sql driver everything worked fine. Not sure how ms-sql-driver and sqoop work together to ensure compatibility with sql server 2005.

Resources