Scripts produced by ApexSQL Diff, which runs fine in SQL Server Management Studio, fail when run from a TFDScript. I am trying to figure out if it is options related, or if it is an implementation problem.
Problem 1: Transaction handing causes an error:
Exception class EMSSQLNativeException with message ‘[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.’.
Problem 2: If I remove the begin tran at line 38/39 and reduce the script to only contain the create table part – it still fails silently. The spool output shows no errors, nor does any errors show in the FireDAC Monitor. And yet – no table is created.
I also suspect that multiline /* block comments */ confuse the script analyzer.
FireDAC Date Handling – FireDAC Date Mystery Part II
As it turns out, the mystery was not fully solved.
After adding map rules (see old post) to FireDAC for how to handle dtTime and dtDate, I removed the old ADO special case handling and just did
Result := FieldByName(FieldName).AsDateTime;
Which worked well – or – so I thought. I had done all my testing on machines that had the SQL Server Native Client installed, and it showed no problems.
But – when I ran on a machine without SQLNCLI installed, the date format issue reared it’s ugly head again.
So – this is the “final” workaround which so far appears to handle every date/time format that I have tossed at it.
function TPSDRecordset.GetAsDateTime(const FieldName: string): TDateTime;
I have an app that connects to a MSSQL db through FireDAC and retrives a selection of log data, including the date and time of the logging in a datetime field.
I leave the app open for a longer period of time (about an hour, I think), then I refresh the view.
BAM! The dates show up as 1899. For some reason, FireDAC has decided to forget how to get the datetime in the right format.
I suspect that is is related to a connection object that has lost it’s connection, but why can it reconnect and get data, and yet get the date format wrong?
I have an app that connects to a MSSQL db through FireDAC and retrives a selection of log data, including the date and time of the logging in a datetime field.
I leave the app open for a longer period of time (about an hour, I think), then I refresh the view.
BAM! The dates show up as 1899. For some reason, FireDAC has decided to forget how to get the datetime in the right format.
I suspect that is is related to a connection object that has lost it’s connection, but why can it reconnect and get data, and yet get the date format wrong?
MICROSOFT SQL SERVER CONNECTIVITY FEATURE PACK COMPONENTS
Microsoft® SQL Server® 2012 Native Client
Microsoft SQL Server Native Client (SQL Server Native Client) is a single dynamic-link library (DLL) containing both the SQL OLE DB provider and SQL ODBC driver. It contains run-time support for applications using native-code APIs (ODBC, OLE DB and ADO) to connect to Microsoft SQL Server 2005, 2008, 2008 R2, and SQL Server 2012. SQL Server Native Client should be used to create new applications or enhance existing applications that need to take advantage of new SQL Server 2012 features. This redistributable installer for SQL Server Native Client installs the client components needed during run time to take advantage of new SQL Server code name ‘Denali’ features, and optionally installs the header files needed to develop an application that uses the SQL Server Native Client API.
Yet another tidbit. Default stored proc parameter sizing.
The old parameter passing to the stored procedures is done with array of const and variants. No issues with that, until my xml logging feature had the mother of all stack traces, and exceeded 9k bytes in total xml size, upon which the assignment of TFDParam.Value complained that TFDParam.Size was 8002 bytes, and the size of the string was bigger than that.
I recently discovered that some of the few queries that we have that return a large rowset, would max out at 50 rows.
It turns out that TFDQuery.FetchOptions.Mode defaults to fmOnDemand, which means that the query first returns a default of 50 rows, and then fetches 50 more as you MoveNext past the 50 first. Other options are fmAll, fmExactRecsMax, fmManual.
Since we still are in the “make it work” and not in the “make it fast” stage, I switched to using fmAll.
Interestingly, RowCount by default also returns 50 even if the query actually matches more rows. and there is a TFDQuery.FetchOptions.RecordCountMode setting that can be modified, as well: cmFetched, cmVisible, cmAll.
This differs from ADO TQuery, which will retrieve all rows and the full record count by default.
TFDDataSet has the same settings, and there are numerous other tweakable parameters that I need to explore for both of these components..
Doing FireDAC againt MSSQL or PostgreSQL visually is easy, but when I try to do it in code only – I get weird errors and there must be something essential that I miss.
Does anyone have a code only example of how to set up a FireDAC connection?
You must be logged in to post a comment.