Pdo mssql error messages - sql-server

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.

Related

Snowflake ODBC driver and SQL Server Polybase

We're currently running a POC with Snowflake and want to integrate it with our existing on premises SQL Server 2019 data warehouse. I've been playing with the standard ODBC driver provided by snowflake, and can get Polybase to connect and talk to tables in our snowflake instance, however I can't get it to play nice with date based columns:
Msg 105083, Level 16, State 1, Line 1
105083;The following columns in the user defined schema are incompatible with the external table schema for table 'DateTest': 'DATE1' failed to be reflected with the error: 'The detected ODBC SQL_TYPE 11 is not supported for external generic tables.'. Could not reflect the following detected external table columns: 'DATE1' failed to be reflected with the error: 'The detected ODBC SQL_TYPE 11 is not supported for external generic tables.', 'DATE2' failed to be reflected with the error: 'The detected ODBC SQL_TYPE SqlDateTime is not supported for external generic tables.', 'DATE3' failed to be reflected with the error: 'The detected ODBC SQL_TYPE SqlDateTime is not supported for external generic tables.'.
Completion time: 2021-03-02T14:11:52.7221079+10:00
I've attempted to follow the ODBC parameter options mentioned here: https://docs.snowflake.com/en/user-guide/odbc-parameters.html
From what I read, I would've thought this parameter would've solved it, but no luck at least from I can see: odbc_use_standard_timestamp_columnsize
I'm all out of ideas on what/if anything that I can do here. I have found an ODBC driver provided by CDATA that seems to work, but I suspect it is going to cost a lot of money, so would prefer to see if the standard snowflake ODBC driver will work first.

ERROR: Target table [X] does not allow UPDATE Row # [0] in bad file

We are getting this error on Informatica when executing a simple UPDATE command while connecting to SQL Server 2016 SP2. We've tested the service account from SQL Server Management Studio manually and it works fine.
Here is the version of SQL Server we have installed.
Informatica error:
Informatica drivers:
From the error message it looks like you do not have the "Update" enabled for the target under the mapping tab in Session properties. Please select the "Update as Update" for the target as in the below snapshot.
If you are using update strategy you can point to data driven option in session level properties. Make sure you have a primary key available in the target. If you are rejecting any records, use a filter/router to reject the data.
Thank you

How to fix this CLI error in SAS?

I've been getting this error when I try to drop, delete, truncate a table in SQL Server using SAS:
ERROR: CLI error trying to establish connection: [DataDirect][ODBC SQL
Server Wire Protocol driver]Error parsing connect string at
offset 74.
This is the code that's causing it:
proc sql;
connect to odbc(noprompt="Driver={DataDirect 6.1 SQL Server Wire Protocol};99.999.999.99;Port=1433;Database=AAA;Uid=sqluser;Pwd=sqlserverpass;");
execute (drop table dbo.BBB_SUMMARY) by odbc;
disconnect from odbc;
quit;
Append works okay. Does anybody know how to solve this?
"Error parsing connect string at offset 74." is a pretty big clue.
Presuming 99.999.999.99 in your connection string is the ip address of your SQL Server, you might need to change that to HOST=99.999.999.99.
See DataDirect docs
Couldn't speculate why the same seemingly malformed connection string would work for append.

F# Error FS3033 unsupported DbType 'Structured'

I’m trying to query our database in F# but I’m having a lot of errors when I get the data context.
Here is my connection command:
#r "System.Data.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.Linq.dll"
open System
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
type dbSchema = SqlDataConnection<"Data Source=OCPM;Initial Catalog=Nautilus;Integrated Security=SSPI;">
let db = dbSchema.GetDataContext()
147 errors in total are returned after this simple script, I won’t list them all but here are a couple of examples:
Script1.fsx(11,17): error FS3033: The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. Warning : SQM1025: Unable to
extract stored procedure 'utvf_VehiclesSummaryUDT' from SqlServer because parameter 'incident' is the unsupported DbType 'Structured'.
Script1.fsx(11,17): error FS3033: The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. Warning : SQM1014: Unable to
extract stored procedure 'asynch.usp_LBNGBasket' from SqlServer.
Invalid object name '#updatedPriceTab'.
I believe this is due to the complexity of the objects and structures used in our DB. The first error is due to a User-Defined Table Types called udt_IncidentExposure in the function utvf_VehiclesSummaryUDT. The second is because the temporary table #updatedPriceTab is called in asynch.usp_LBNGBasket but created in another stored procedures.
I’m surprised of the limited compatibility between F# and SQL Server on complex structures. Is there any other way to connect to SQL server in F#? All I need is doing very simples SQL queries.
Additional information: SQL Server version in use is 10.50.4270
You are out of luck with using production-quality SqlClient type provider because it requires at least SQL2012 to operate.
You may try SQL Type Provider, although I do not have any experience using it in production scenarios.
Also you may try using SqlEntityConnection type provider that sometimes does better job, than SqlDataConnection type provider that you've tried.
And finally, as the last resort, nothing prevents you from accessing SQL from F# through plain ADO.NET.
You can try other F# type providers from here:
http://fsharp.org/guides/data-access/#sql-data-access
The best one (IMO) for MS SQL Server is FSharp.Data.SqlClient but I believe it supports only version 2012 and up.

ogr2ogr to import GML with spatial and non-in 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.

Resources