[PHP PDO / SQL Server] Fatsoenlijke error messages

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Steven
  • Registratie: December 2000
  • Laatst online: 05-07 21:17
Goededag,

Voor een applicatie die ik aan het ontwikkelen moet ik gebruik maken van een MS SQL Server 2005 database. Het leek me handig om van de PDO class gebruik te maken, vooral aangezien die prepared statements ondersteund. Nu heb ik het aan de praat, alleen krijg ik hele irritante foutmeldingen terug als er een fout in een query zit. Er wordt een Exception gegooid met de volgende message:

code:
1
Uncaught exception: <i>SQLSTATE[HY000]: General error: 156 General SQL Server error: Check messages from the SQL Server [156] (severity 15) [(null)]


In de server logs is verder ook niets interessants te vinden. Als ik van het QueryObject errorinfo() print_r krijg ik het volgende aan info:
code:
1
2
3
4
5
6
7
8
Array
(
    [0] => HY000
    [1] => 156
    [2] => General SQL Server error: Check messages from the SQL Server [156] (severity 15) [(null)]
    [3] => 0
    [4] => 15
)


Niet heel veel nuttiger. Op internet kan ik hier helemaal niets over vinden. Heeft iemand enig idee wat ik over het hoofd zie of wat ik anders aan moet pakken?

Acties:
  • 0 Henk 'm!

  • Spiked
  • Registratie: Mei 2008
  • Laatst online: 17-09 15:30
Misschien even handig om de query in kwestie te posten?

Acties:
  • 0 Henk 'm!

Verwijderd

Je kunt de exception catchen en met getTraceAsString() het een en ander achterhalen, o.a. de query :)
Voor de rest een kwestie van de errorcode opzoeken lijkt me.

Acties:
  • 0 Henk 'm!

  • Cartman!
  • Registratie: April 2000
  • Niet online
Ik krijg met PDO gewoon normale foutmeldingen terug, misschien heb je gewoon een exotische fout te pakken met je query? Dan kan PDO zelf daar weinig aan doen, die stuurt je gewoon de foutmelding van de SQL engine.

Acties:
  • 0 Henk 'm!

  • wackmaniac
  • Registratie: Februari 2004
  • Laatst online: 17-09 10:24
Even zoeken op mssql exception 156 geeft het volgende resultaat:

http://msdn.microsoft.com...aa258712%28SQL.80%29.aspx
Error 156
Severity Level 15
Message Text

Incorrect syntax near the keyword '%.*ls'.
Explanation

This error indicates that the syntax of a Transact-SQL statement is incorrect and that the syntax error was detected near the keyword specified in the error message. The most frequent causes for syntax errors are misspellings of Transact-SQL keywords or operators, and specifying the syntax of a Transact-SQL statement in the wrong order.

One of the more complicated causes for this error may be a compatibility level mismatch for the current database. If the current database has a compatibility level other than 70, Microsoft® SQL Server™ will not recognize any of the keywords that a database with a compatibility level of 70 would recognize.
Action

First, check the Transact-SQL statement syntax near the keyword specified in the error message. Because Transact-SQL language syntax can be very complex, SQL Server may incorrectly report the position of the syntax error as later in the Transact-SQL statement than it actually occurred. Second, reexamine the entire Transact-SQL statement that generated the error. Verify the syntax order of the statement.

Ensure that the database does not have a compatibility level of 65 and has a compatibility level of 70.
Ik denk een slechte driver die de fouten niet vertaald, maar met het foutnummer kan je een heel eind komen dus :)

Read the code, write the code, be the code!